Android 使用json返回html标记的服务器响应
我正在使用以下函数向服务器发送字符串值,但返回值为:Android 使用json返回html标记的服务器响应,android,json,Android,Json,我正在使用以下函数向服务器发送字符串值,但返回值为: <html><html> 返回值必须为:1或-1或0 我的问题是什么?可能是服务器端的问题。检查那边的代码。现在我正在使用截击库,它工作正常。。。 public static String POST(String url, String person){ InputStream inputStream = null; String result = ""; try { Htt
<html><html>
返回值必须为:1或-1或0
我的问题是什么?可能是服务器端的问题。检查那边的代码。现在我正在使用截击库,它工作正常。。。
public static String POST(String url, String person){
InputStream inputStream = null;
String result = "";
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
String json = "";
JSONObject jsonObject = new JSONObject();
jsonObject.put(person, person);
json = jsonObject.toString();
StringEntity se = new StringEntity(json);
httpPost.setEntity(se);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
HttpResponse httpResponse = httpclient.execute(httpPost);
inputStream = httpResponse.getEntity().getContent();
if(inputStream != null)
result = convertInputStreamToString(inputStream);
else
result = "Did not work!";
} catch (Exception e) {
Log.d("InputsStream", e.getLocalizedMessage());
}
// 11. return result
Log.e("result", result);
return result;
}
private static String convertInputStreamToString(InputStream inputStream) throws IOException{
BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
String line = "";
String result = "";
while((line = bufferedReader.readLine()) != null)
result += line;
inputStream.close();
return result;
}