httpclient使用

public static void main(String[] args) throws ClientProtocolException, IOException, InvalidKeyException, NoSuchAlgorithmException {
         HttpClient httpclient = new DefaultHttpClient();
         List<NameValuePair> list = new ArrayList<NameValuePair>();
         list.add(new BasicNameValuePair("bill_id","06757487"));
         list.add(new BasicNameValuePair("status","paid"));
         list.add(new BasicNameValuePair("error","0"));
         list.add(new BasicNameValuePair("user","123"));
         Map<String,String> map = new HashMap<String, String>();
         map.put("bill_id","06757487");
         map.put("status","paid");
         map.put("error","0");
         map.put("user","123");
         String src = generateSignString(map);
         String sign = DigestUtil.getHAMC_SHA1Signature(src, "SNVDTLDHTBDNLYV");
         HttpPost post = new HttpPost("http://localhost:8082/lcpay_notify/qiwiNotify");
            post.setHeader("Accept", "application/xml");
            post.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
            post.setHeader("X-Api-Signature",sign);
            UrlEncodedFormEntity formEntity = null;
            formEntity = new UrlEncodedFormEntity(list, "utf-8");
            post.setEntity(formEntity);
            // 发起交易
            HttpResponse resp = httpclient.execute(post);
            HttpEntity entity = resp.getEntity();
            BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8"));
            StringBuffer responseString = new StringBuffer();
            String result = br.readLine();
            while (result != null) {
                responseString.append(result);
                result = br.readLine();
            }
            System.out.println(responseString);



欢迎关注公众号:Java后端技术全栈