设为首页 加入收藏

TOP

Android URL请求的方法 迭代器
2014-11-24 08:32:21 来源: 作者: 【 】 浏览:1
Tags:Android URL 请求 方法

protected static CommResult HttpPost(Context context, String url,
HashMap map) {
synchronized ("http post") {
CommResult result = new CommResult();


HttpClient httpClient = getNewHttpClient(context);


HttpPost httpPost = new HttpPost(url);


ArrayList postDate = new ArrayList();


Set set = map.keySet();


Iterator iterator = set.iterator();


while (iterator.hasNext()) {
String key = (String) iterator.next();
postDate.add(new BasicNameva luePair(key, map.get(key)));


}
try {
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(
postDate, HTTP.UTF_8);
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost);


InputStream in = response.getEntity().getContent();
int statusCode = response.getStatusLine().getStatusCode();
String message = InputStreamToString(in);


result.setMessage(message);
result.setResponseCode(String.valueOf(statusCode));


} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}


return result;
}
}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇.bash_profile .bashrc profile .. 下一篇C#中正则表达式的使用实例

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·定义一个类模板并实 (2025-12-27 06:52:28)
·一文搞懂怎么用C语言 (2025-12-27 06:52:25)
·常用C模板范文_百度 (2025-12-27 06:52:21)
·【C语言】动态内存管 (2025-12-27 06:23:20)
·C语言中的内存管理 - (2025-12-27 06:23:16)