java httpclient发送post get 请求
2011-04-22 09:59
696 查看
import java.io.IOException;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
public class SimpleHttpClient {
public static void main(String[] args) throws IOException
{
HttpClient client = new HttpClient();
int i =0;
while( i<1000){
client.getHostConfiguration().setHost("60.217.249.98", 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();
i++;
}
}
/**
* 使用GET方式提交数据
* @return
*/
/* private static HttpMethod getGetMethod(){
return new GetMethod(" ");
}*/
/**
* 使用POST方式提交数据
* @return
*/
private static HttpMethod getPostMethod(){
PostMethod post = new PostMethod("/content/refresh");
NameValuePair username = new NameValuePair("username","chinacache");
NameValuePair password = new NameValuePair("password","chinacache");
NameValuePair task = new NameValuePair("task","{urls:[/"http://test.gamedl.qq.chinacache.net/"]}");
post.setRequestBody(new NameValuePair[] { username,password,task});
return post;
}
}
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
public class SimpleHttpClient {
public static void main(String[] args) throws IOException
{
HttpClient client = new HttpClient();
int i =0;
while( i<1000){
client.getHostConfiguration().setHost("60.217.249.98", 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();
i++;
}
}
/**
* 使用GET方式提交数据
* @return
*/
/* private static HttpMethod getGetMethod(){
return new GetMethod(" ");
}*/
/**
* 使用POST方式提交数据
* @return
*/
private static HttpMethod getPostMethod(){
PostMethod post = new PostMethod("/content/refresh");
NameValuePair username = new NameValuePair("username","chinacache");
NameValuePair password = new NameValuePair("password","chinacache");
NameValuePair task = new NameValuePair("task","{urls:[/"http://test.gamedl.qq.chinacache.net/"]}");
post.setRequestBody(new NameValuePair[] { username,password,task});
return post;
}
}
相关文章推荐
- java apache commons HttpClient发送get和post请求的学习整理
- httpclient发送post/get请求,Java后台怎么接受
- java发送post和get请求(1)---HttpClient 方式
- java apache commons HttpClient发送get和post请求的学习整理
- HttpClient详解,Java发送Http的post、get方式请求 --待整理
- java apache commons HttpClient发送get和post请求的学习整理
- java apache commons HttpClient发送get和post请求的学习整理
- Java代码中利用httpClient发送post、get请求
- java apache commons HttpClient发送get和post请求的学习整理
- java apache commons HttpClient发送get和post请求的学习整理
- Java用HttpClient3发送Get和Post请求(增强)
- java apache commons HttpClient发送get和post请求的学习整理
- java apache commons HttpClient发送get和post请求的学习整理(转)
- java发送http的get、post请求
- java发送http的get、post请求
- 多种方式实现(jdk原生api实现/httpClient的实现) java 发送http(post/get)请求并携带参数(讲解超详细)
- java 利用httpclient 3.1 和 httpclient4.1.2发送post请求
- java发送http的get和post请求
- Java中发送Http请求Get、Post
- java发送http的get、post请求