public static JSONObject HttpPostAnswerJsonObject(String url, JSONObject obj) throws ClientProtocolException, IOException, JSONException, HttpException{
AndroidHttpClient client = AndroidHttpClient.newInstance(null);
client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 60000);
client.getParams().setParameter(HttpConnectionParams.SO_TIMEOUT, 60000);
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new StringEntity(obj.toString()));
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
HttpResponse response = client.execute(httpPost);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
String raw = EntityUtils.toString(response.getEntity());
JSONObject jobj = new JSONObject(raw);
client.close();
return jobj;
} else {
try {
client.close();
}catch (Exception ex){}
throw new HttpException("STATUSCODE!=200");
}
}
ServiceData.java 文件源码
java
阅读 35
收藏 0
点赞 0
评论 0
项目:otrta
作者:
评论列表
文章目录