设为首页 加入收藏

TOP

Android URL请求的方法 迭代器
2014-11-24 08:32:21 来源: 作者: 【 】 浏览:0
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#中正则表达式的使用实例

评论

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

·如何理解c语言指针和 (2025-12-27 01:19:11)
·为什么C标准库没有链 (2025-12-27 01:19:08)
·玩转C语言和数据结构 (2025-12-27 01:19:05)
·MySQL 基础入门视频 (2025-12-26 23:20:22)
·小白入门:MySQL超详 (2025-12-26 23:20:19)