0
HttpURLConnection DELETE 메서드로 url 매개 변수를 보내는 방법은 무엇입니까?HttpURLConnection URL 매개 변수로 DELETE
내가 코드 아래 사용하고 있습니다 :
나는 항상 무효 initiator_id으로 반응을 얻고있다 위의 코드를 실행하고String targetURL = "http://example.com/some:data?initiator_id=6724181421";
URL url = new URL(targetURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty ("dev_key", "12345");
connection.setReadTimeout(60000);
connection.setConnectTimeout(60000);
connection.setRequestMethod("DELETE");
connection.addRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
int responseCode = connection.getResponseCode();
if(responseCode == HttpURLConnection.HTTP_OK){
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response = new StringBuffer();
while((line = rd.readLine()) != null) {
response.append(line);
response.append('\r');
}
rd.close();
}
. 나는 우편 배달부와 곱슬 곱슬하게 똑같은 것을 시험해 보았습니다. 컬 (curl)과 포스트 만 (Postman) 모두에서 효과가 있습니다.
'initiator_id'를 검색어 매개 변수 (url의 일부) 또는 양식 매개 변수 (요청 본문에 삽입 됨)로 설정하려고합니까? – dnault
검색어 매개 변수 (URL의 일부)로 추가하려고합니다. 양식 매개 변수로 추가하려고하면 "HTTP 메서드 DELETE가 출력을 지원하지 않습니다." –
양식 매개 변수를 DataOutputStream wr = new DataOutputStream (connection.getOutputStream()); wr.writeBytes ("initiator_id = 6724181421"); wr.flush(); wr.close(); 그러나 예외 "HTTP 메서드 DELETE는 출력을 지원하지 않습니다."Java 1.8에서 수정 된 –