Как отправить параметры URL-адреса с помощью метода HttpURLConnection DELETE?
Я использую код ниже:
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();
}
Когда я выполняю приведенный выше код, я всегда получаю ответ как недопустимый initiator_id. Я тестировал то же самое с Postman и curl. И в curl, и в Postman это работает.
initiator_id
в качестве параметра запроса (часть URL-адреса) или в качестве параметра формы (встроенного в тело запроса)? - person dnault   schedule 24.06.2016