「Android」doPost()でJSON文字列を取得する方法

javaコード
public static String doPost(List<NameValueSample> params, String url)
throws Exception {
String result = null;
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
if (params != null) {

HttpEntity entity = new UrlEncodedFormEntity(params, HTTP.UTF_8);
httpPost.setEntity(entity);
}

HttpResponse httpResp = httpClient.execute(httpPost);
if (httpResp.getStatusLine().getStatusCode() == 200) {
result = EntityUtils.toString(httpResp.getEntity(), “UTF-8");
} else {
Log.i(“HttpPost", “HttpPost method request failure");
}

return result;
}

Android

Posted by arkgame