ServiceData.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:otrta 作者:
public static JSONArray HttpPostAnswerJsonArray(String url, JSONObject obj) throws ClientProtocolException, IOException, JSONException, HttpException{
    AndroidHttpClient client = AndroidHttpClient.newInstance(null);
    client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 10000);
    client.getParams().setParameter(HttpConnectionParams.SO_TIMEOUT, 10000);
    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());
        JSONArray jarr = new JSONArray(raw);
        client.close();
        return jarr;
    } else {
        try {
            client.close();
        }catch (Exception ex){}
        throw new HttpException("STATUSCODE!=200");
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号