- GET: работает нормально.
- POST/PUT: Http-ошибка 400, неверный запрос — неверный заголовок. хотя
Apache HttpClient:
Код: Выделить всё
HttpPut put = new HttpPut();
StringEntity se = new StringEntity(json);
se.setContentEncoding("UTF-8");
se.setContentType("application/json");
put.setEntity(se);
response = client.execute(put);
Код: Выделить всё
// API
@PUT("/
")
Response updateThing(@Body Dto dto);
// OkHttpClient
@Override
public Response execute(Request r) throws IOException {
List headers = HttpHelper.headerFor(method, url, etc);
// Create new request with required headers
Request encodedRequest = new Request(method, url, headers, r.getBody());
return super.execute(encodedRequest);
}
Код: Выделить всё
---> HTTP PUT https://example.com/path
Content-Type: application/json; charset=UTF-8
Content-Length: 53
{"user_id":"0","latitude":"0.0","longitude":"0.0"}
---> END HTTP (53-byte body)
PUT https://example.com/path
Authorization Basic bmfweEskWkvlabF0ZSQ=
Content-Type application/json
Accept application/json
HashKey 8eb93b898ddc2b74685ed2be64c76cc3af973ebc6b628781fe50eedcbe29376f
Подробнее здесь: [url]https://stackoverflow.com/questions/20918976/http-400-bad-request-invalid-header-with-retrofit-on-android[/url]