简单的httpclient post请求

  public static void main(String[] args) throws ClientProtocolException, IOException {
        String str = "http://www.baidu.com";
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(str);
        try {
            List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
            params.add(new BasicNameValuePair("sign", "测试"));
            post.setEntity(new UrlEncodedFormEntity(params,"UTF-8"));
            HttpResponse response = client.execute(post);
            System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

 

posted @ 2013-04-07 22:10  博宏  阅读(204)  评论(0编辑  收藏  举报