Android(安卓)Post方法请求URL 迭代器
16lz
2022-03-16
protected static CommResult HttpPost(Context context, String url,HashMap<String, String> map) {synchronized ("http post") {CommResult result = new CommResult();HttpClient httpClient = getNewHttpClient(context);HttpPost httpPost = new HttpPost(url);ArrayList<BasicNameValuePair> postDate = new ArrayList<BasicNameValuePair>();Set<String> set = map.keySet();Iterator<String> iterator = set.iterator();while (iterator.hasNext()) {String key = (String) iterator.next();postDate.add(new BasicNameValuePair(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;}}
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer