欢迎进入Java社区论坛,与200万技术人员互动交流 >>进入
//将表单的值放入postMethod中
postMethod.setRequestBody(data);
try {
//执行postMethod
int statusCode = httpClient.executeMethod(postMethod); // HttpClient对于要求接受后继服务的请求,象POST和PUT等不能自动处理转发
// 301或者302
if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
//从头中取出转向的地址
Header locationHeader = postMethod
.getResponseHeader(“location”);
String location = null;
if (locationHeader != null) { location = locationHeader.getValue(); System.out .println(“The page was redirected to:” + location);
} else {
System.err.println(“Location field value is null.”);
}
}
body = postMethod.getResponseBody();
} catch (Exception e) {
e.printStackTrace();
}
return body;
}
public static void main(String[] args) {
String url=“http://www.xfok.net”;
Map parms=new HashMap();
MyClient client=new MyClient();
String result=new String(client.getBody(url, parms)); System.out.println(result);
}
}
出处:http://www.xfok.net/2009/10/124488.html
[1][2]
灯红酒绿的城市,登上楼顶,俯视万家灯火,