我使用下面的java代碼創建了Web服務調用。現在我需要進行刪除和放置操作。在HttpURLConnection中發送PUT,刪除HTTP請求
URL url = new URL("http://example.com/questions");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
OutputStream os = conn.getOutputStream();
os.write(jsonBody.getBytes());
os.flush();
當我添加以下代碼來執行DELETE操作它給錯誤說:
java.net.ProtocolException:HTTP方法刪除不支持輸出。
conn.setRequestMethod("DELETE");
那麼如何進行刪除,並把請求?
請原諒喊,但**沒有給出什麼**錯誤?另外,我會建議['HttpClient'](http://hc.apache.org/httpcomponents-client-ga/index.html)來自apache。 –
編輯了這個問題。任何Web服務請求的示例代碼?任何幫助? – manitaz
是否http://stackoverflow.com/questions/1051004/how-to-send-put-delete-http-request-in-httpurlconnection幫助? – hgoebl