































*/
public class SimpleHttpClient {
public static void main(String[] args) throws IOException
{
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost("doc.guandang.net;, 80, "http");
HttpMethod method = getPostMethod();//使用POST方式提交数据 client.executeMethod(method);
//打印服务器返回的状态
System.out.println(method.getStatusLine());
//打印结果页面
String response = new String(method.getResponseBodyAsString().getBytes("8859_1"));
//打印返回的信息
System.out.println(response);
method.releaseConnection();
}
/**
* 使用GET方式提交数据
* @return
*/
private static HttpMethod getGetMethod(){
return new GetMethod("/simcard.php?simcard=1330227");
}
/**
* 使用POST方式提交数据
* @return
*/
private static HttpMethod getPostMethod(){
PostMethod post = new PostMethod("/simcard.php");
NameValuePair simcard = new NameValuePair("simcard","1330227"); post.setRequestBody(new NameValuePair[] { simcard});
return post;
}
}
在上面的例子中页面doc.guandang.net需要一个参数是
simcard,这个参数值为手机号码段,即手机号码的前七位,服务器会返回提交的手机号码对应的省份、城市以及其他详细信息。GET的提交方法只需要在URL后加入参数信息,而POST则需要通过NameValuePair类来设置参数名称和它所对应的值
3. 处理页面重定向
httpclient模拟post请求_互联网_IT/计算机_专业资料。import java.io.Buffered...("Method is wrong " + postMethod.getStatusLine()); } InputStream ...
采用Jakarta的HttpClient API模拟客户端GET和POST提交_IT/计算机_专业资料。采用...HttpClient 扩展和增强了标准 java.net 包,是一个内容广泛的代码库,功能极 其...
源文档 <http://www.jiucool.com/java-sending-http-requests-get-and-post-method-request/> JAVA-用 HttpClient 来模拟浏览器 GET,POST 七月 9, 2009 ...
HTTP POST GET 本质区别详解 收藏 一原理区别 一般在浏览器中输入网址访问资源... JAVA-用HttpClient来模拟... 8页 1下载券 HTTP协议详解 12页 1下载券 ...
Android之用HTTP的get,post,HttpClient三种方式向service提交文本数据_计算机软件... JAVA-用HttpClient来模拟... 8页 1下载券喜欢此文档的还喜欢...
java.io.BufferedReader; java.io.IOException; java.io.InputStream; java.io...Get; org.apache.http.client.methods.HttpPost; org.apache.http.impl.client...
GetMethod("http://java.sun.com"); //使用POST方法 //HttpMethod method =... JAVA-用HttpClient来模拟... 8页 1下载券2014 Baidu 使用百度前必读 ...
以及如何使用 HttpClient 来简化 Get 和 Post 请求操作,构建强大的网络应用程 ...wd=Thinking+In+Java 。而 PostMethod 则可以模拟网页里表单提交的过程, 通过...
实现了所有 HTTP 的方法(GET,POST,PUT,HEAD 等) 支持自动转向 支持 HTTPS ... import java.util.Vector; import org.apache.commons.httpclient.Cookie; ...
利用通过建立穿过 HTTP 代理的 HTTPS 连接 利用本地 Java socket,透明地穿过 ...4.4 重定向问题 Httpclient 的 get 的方法支持自动转向处理,而 post 方法不...
热门文档