如何在HttpURLConnection中发送PUT,DELETE HTTP请求?

如何在HttpURLConnection中发送PUT,DELETE HTTP请求?,第1张

如何在HttpURLConnection中发送PUT,DELETE HTTP请求

执行HTTP PUT:

URL url = new URL("http://www.example.com/resource");HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();httpCon.setDoOutput(true);httpCon.setRequestMethod("PUT");OutputStreamWriter out = new OutputStreamWriter(    httpCon.getOutputStream());out.write("Resource content");out.close();httpCon.getInputStream();

要执行HTTP删除:

URL url = new URL("http://www.example.com/resource");HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();httpCon.setDoOutput(true);httpCon.setRequestProperty(    "Content-Type", "application/x-www-form-urlenpred" );httpCon.setRequestMethod("DELETE");httpCon.connect();


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5146491.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-18
下一篇 2022-11-17

发表评论

登录后才能评论

评论列表(0条)

保存