1、HTTP请求URI (协议模式,主机名称,可选的端口,资源路径,可选的查询和可选的片段。)
结果为:http://www.google.com/search?q=httpclient&btnG=Google+Search&aq=f&oq=
2.查询字符串也可以从独立的参数中来生成:
paramList.add(new BasicNameValuePair("username", loginUsername));
paramList.add(new BasicNameValuePair("password", loginPassword));
HttpPost httpPost = new HttpPost(loginUrl);
例:HttpGet httpget = new HttpGet("http://www.google.com/search?hl=en&q=httpclient&btnG=Google+Search&aq=f&oq=");
2、设置URI(设置HTTP请求参数)
- URI拼装:
结果为:http://www.google.com/search?q=httpclient&btnG=Google+Search&aq=f&oq=
2.查询字符串也可以从独立的参数中来生成:
3.List<NameValuePair> paramList = new ArrayList<NameValuePair>();List<NameValuePair> qparams = new ArrayList<NameValuePair>();
qparams.add(new BasicNameValuePair("q", "httpclient"));
qparams.add(new BasicNameValuePair("btnG", "Google Search"));
qparams.add(new BasicNameValuePair("aq", "f"));
qparams.add(new BasicNameValuePair("oq", null));
URI uri = URIUtils.createURI("http", "www.google.com", -1, "/search",URLEncodedUtils.format(qparams, "UTF-8"), null);
paramList.add(new BasicNameValuePair("username", loginUsername));
paramList.add(new BasicNameValuePair("password", loginPassword));
HttpPost httpPost = new HttpPost(loginUrl);
httpPost.setEntity(new UrlEncodedFormEntity(paramList));
3.HTTP实体