首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

HttpClient4 参数传递步骤

2012-11-10 
HttpClient4 参数传递方法HttpClient httpclient new DefaultHttpClient()//设置代理服务器HttpHost pr

HttpClient4 参数传递方法

HttpClient httpclient = new DefaultHttpClient();//设置代理服务器HttpHost proxy = new HttpHost(Config.getProxyHost(), Config.getProxyHostPort());//将代理服务器信息添加的httpclienthttpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);HttpPost httppost = new HttpPost(Config.getLoginUrl());//建立参数列表List<NameValuePair> params = new ArrayList<NameValuePair>();//开始添加参数params.add(new BasicNameValuePair("username",Config.getLoginName()));params.add(new BasicNameValuePair("password",Config.getPassword()));UrlEncodedFormEntity uefEntity = null;HttpResponse response = null;HeaderElement element = null;try {        //将参数进行编码uefEntity = new UrlEncodedFormEntity(params, "UTF-8");        //将参数添加的POST请求中httppost.setEntity(uefEntity);response = httpclient.execute(httppost);Header header = response.getLastHeader("Set-Cookie");element = header.getElements()[0];} catch (ClientProtocolException e1) {e1.printStackTrace();} catch (IOException e1) {e1.printStackTrace();} finally {httpclient.getConnectionManager().shutdown();}

热点排行