HttpPost客户端请求实例
2014-03-05 17:25
441 查看
public static void main(String[] args) throws Exception { // TODO Auto-generated method stub String url="http://localhost/newspaper/test/1.php"; //POST的URL HttpPost httppost=new HttpPost(url); //建立HttpPost对象 List<NameValuePair> params=new ArrayList<NameValuePair>(); //建立一个NameValuePair数组,用于存储 传送的参数 params.add(new BasicNameValuePair("pwd","2544")); //添加参数 httppost.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8)); //设置编码 HttpResponse response=new DefaultHttpClient().execute(httppost); //发送Post,并返回一个HttpResponse对象 //Header header = response.getFirstHeader("Content-Length"); //String Length=header.getValue(); // 上面两行可以得到指定的Header if(response.getStatusLine().getStatusCode()==200){//如果状态码为200,就是正常返回 String result=EntityUtils.toString(response.getEntity()); //得到返回的字符串 System.out.println(result); //如果是下载文件,可以用response.getEntity().getContent()返回InputStream } }
相关文章推荐
- http post 客户端请求
- 客户端HTTP Header 请求实例
- c# http get请求与post请求实例
- java 作为客户端发送http post请求登录网站首页。 HTTP/1.1 302 Found
- Android HTTP实例 使用GET方法和POST方法发送请求
- C#模拟http 发送post或get请求的简单实例
- Android客户端采用Http 协议Post方式请求与服务端进行数据交互(转)
- Android客户端采用Http 协议Post方式请求与服务端进行数据交互
- JAVA Socket 实现HTTP与HTTPS客户端发送POST与GET方式请求
- ASIHTTPRequest中的DELETE、PUT、GET、POST请求实例-备用
- C# Http 发送Post请求实例
- HTTP客户端发送Post和Get请求
- JAVA_http的post请求 实例
- linux下纯C简单的HTTP POST请求 客户端模型
- Android平台HttpGet、HttpPost请求实例
- Spring框架中接收Http客户端的Post和Get请求
- Android客户端采用Http 协议Post方式请求与服务端进行数据交互
- Android HTTP实例 使用GET方法和POST方法发送请求
- JAVA Socket 实现HTTP与HTTPS客户端发送POST与GET方式请求
- 02.HTTP协议之客户端实现(POST请求)