Ошибка воспроизводится с компьютера только если посылать POST запрос.
При этом GET запросы работают нормально
Собственно сам вопрос, действительно ли android посылает PUT, а не пост запрос? Может нужны какие-нибудь дополнительные заголовки?
Пробовал и HttpURLConnection и DefaultHttpClient.
Код: Выделить всё
public static JSON createFromNet(String url, String method, String params){
String json = "{}";
try{
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpUriRequest httpRequest = null;
if (method == "GET"){
httpRequest = JSON.getGetRequest(url);
}
if (method == "PUT"){
httpRequest = JSON.getPutRequest(url, params);
}
if (httpRequest == null){
throw new Exception();
}
HttpResponse httpResponse = httpClient.execute(httpRequest);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream is = httpEntity.getContent();
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();
}catch (UnsupportedEncodingException e) {
}catch (ClientProtocolException e) {
}catch (IOException e) {
}catch (Exception e) {
}
return new JSON(json);
}
protected static HttpUriRequest getPutRequest(String url, String params) throws UnsupportedEncodingException{
StringEntity input = new StringEntity(params);
input.setContentType("application/json");
input.setContentEncoding("UTF-8");
HttpPut request = new HttpPut(url);
request.setEntity(input);
return request;
}
protected static HttpUriRequest getGetRequest(String url){
return new HttpGet(url);
}