Я создаю приложение для Android, которое использует конечную точку запроса API Uber API. У меня возникают проблемы с добавлением данных в HTTPBody, и в нем отображается ошибка, так как конечные точки не поддерживаются.Как добавить данные в HTTPBody с помощью метода put в android
Это локон команда:
curl -X PUT 'https://sandbox-api.uber.com/v1/sandbox/requests/{REQUEST_ID}'
\ -H 'Content-Type: application/json'
\ -H 'Authorization: Bearer '
\ -d '{"status":"accepted"}'
Код:
public JSONObject getStatus(String address, String requestId, String product_id, float start_latitude, float start_longitude, float end_latitude, float end_longitude, String token) {
try {
httpClient = new DefaultHttpClient();
httpput = new HttpPut("https://sandbox-api.uber.com/v1/requests/"+requestId);
**params.add(new BasicNameValuePair("status", "accepted"));**
httpput.setHeader("Authorization","Bearer "+token);
httpput.setHeader("Content-type", "application/json");
httpput.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpput);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "n");
}
is.close();
json = sb.toString();
Log.e("JSONStr", json);
} catch (Exception e) {
e.getMessage();
Log.e("Buffer Error", "Error converting result " + e.toString());
}
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
return jObj;
}
Как ожидает сервер PUT? JSON? XML? URL-закодированы? – Bhargav
Требуется формат json –
Фактически я не получаю, как добавить статус в HTTPbody –