日期:2014-05-19 浏览次数:20748 次
HttpPost httpost = new HttpPost(url);
// 添加参数
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
if (params != null && params.keySet().size() > 0) {
Iterator iterator = params.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry entry = (Entry) iterator.next();
nvps.add(new BasicNameValuePair((String) entry.getKey(),
(String) entry.getValue()));
}
}
httpost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));
HttpResponse response = httpclient.execute(httpost);
HttpEntity entity = response.getEntity();
System.out.println("Login form get: " + response.getStatusLine()
+ entity.getContent());
dump(entity, encoding);
System.out.println("Post logon cookies:");
List<Cookie> cookies = httpclient.getCookieStore().getCookies();
if (cookies.isEmpty()) {
System.out.println("None");
} else {
for (int i = 0; i < cookies.size(); i++) {
System.out.println("- " + cookies.get(i).toString());
}
}
DefaultHttpClient httpclient = new DefaultHttpClient(
new ThreadSafeClientConnManager());
try {
HttpPost httpost = new HttpPost(url);
// 添加参数
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
if (params != null && params.keySet().size() > 0) {
Iterator iterator = params.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry entry = (Entry) iterator.next();
nvps.add(new BasicNameValuePair((String) entry.getKey(),
(String) entry.getValue()));