Android URL请求的技巧 迭代器
发布时间:2021-11-21 21:36:52 所属栏目:教程 来源:互联网
导读:Android URL请求的方法 迭代器 protected static CommResult HttpPost(Context context, String url, HashMapString, String map) { synchronized (http post) { CommResult result = new CommResult(); HttpClient httpClient = getNewHttpClient(context);
Android URL请求的方法 迭代器 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; } } ![]() (编辑:江门站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |