Я делаю то, что должно быть простым постом http, который содержит строку json в качестве тела http.
? 
Все выглядит хорошо, кроме самого ответа - когда япревратить его в строку, он выглядит странно (не текст).Как я могу получить это в виде простого текста?Или что я сделал не так во время поста чтобы получить этот ответ?(примечание - если я исключаю файлы cookie во время процедуры POST, я получаю простой html-файл с сервера с действительным сообщением «отказано в доступе»)
Полный код этого решения ниже
public class BaseHttpService {
public ResponseAndCookies doHttpPostWithUrlWithJson(String url, String key, CookieStore cookies) {
try {
StringEntity se = new StringEntity("{\"filters\":true}");
se.setContentType("text/xml");
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
HttpPost httpost = new HttpPost(url);
httpost.setEntity(se);
httpost.setHeader("Accept", "application/json");
httpost.setHeader("Content-Type", "application/json");
return executeHttpRequest(httpost, cookies);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
public ResponseAndCookies executeHttpRequest(HttpRequestBase http, CookieStore cookieStore) {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
String result = "";
if (cookieStore != null) {
((DefaultHttpClient) httpclient).setCookieStore(cookieStore);
}
try {
response = httpclient.execute(http);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
result = convertStreamToString(instream);
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
List<Cookie> cookies = ((DefaultHttpClient) httpclient).getCookieStore().getCookies();
CookieStore postCookieStore = ((DefaultHttpClient) httpclient).getCookieStore();
ResponseAndCookies x = new ResponseAndCookies();
x.setCookies(cookies);
x.setResponse(result);
x.setCookieStore(postCookieStore);
httpclient.getConnectionManager().shutdown();
return x;
}
public static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
}