???HttpClient????????????
???????????? ???????[ 2016/2/1 11:47:40 ] ??????????????? ??????
???????????????У?????鳤???????????????????????£??????httpЭ?飬????????????????httpClient???????????????????飬??????????????????????????demo?????????????????????????????????????????demo?????????????????????????????????????????????????в????????????????????????????????
?????????jar????
1packagecom.lym.test;
2
3importorg.apache.http.HttpEntity;
4importorg.apache.http.HttpHost;
5importorg.apache.http.client.config.RequestConfig;
6importorg.apache.http.client.methods.CloseableHttpResponse;
7importorg.apache.http.client.methods.HttpPost;
8importorg.apache.http.entity.StringEntity;
9importorg.apache.http.impl.client.CloseableHttpClient;
10importorg.apache.http.impl.client.HttpClientBuilder;
11importorg.apache.http.util.EntityUtils;
12
13importcom.google.gson.JsonObject;
14
15publicclassHttpClientTest{
16
17publicstaticvoidmain(Stringargs[])throwsException{
18
19//????HttpClientBuilder
20HttpClientBuilderhttpClientBuilder=HttpClientBuilder.create();
21//HttpClient
22CloseableHttpClientcloseableHttpClient=httpClientBuilder.build();
23//??????????????????????Э??????
24HttpHosttarget=newHttpHost("61.144.244.6:8888/sztmerchant/merchant/addIsztMerchant.htm"??8888??"http");
25//?????????????????????Э??????
26HttpHostproxy=newHttpHost("proxy3.bj.petrochina"??8080??"http");
27RequestConfigconfig=RequestConfig.custom().setProxy(proxy).build();
28
29//??????
30HttpPosthttpPost=newHttpPost("http://61.144.244.6:8888/sztmerchant/merchant/addIsztMerchant.htm");
31//????????
32httpPost.addHeader("Content-type"??"application/json;charset=utf-8");
33httpPost.setHeader("Accept"??"application/json");
34httpPost.setConfig(config);
35
36//????????json??
37JsonObjectjsonObj=newJsonObject();
38jsonObj.addProperty("merchantNo"??"33300911238");
39jsonObj.addProperty("merchantName"??"???????????????1238");
40StringjsonStr=jsonObj.toString();
41System.out.println("parameters:"+jsonStr);
42
43StringEntityentity;
44try{
45entity=newStringEntity(jsonStr??"UTF-8");
46httpPost.setEntity(entity);
47CloseableHttpResponseresponse=closeableHttpClient.execute(target??httpPost);
48//getEntity()
49HttpEntityhttpEntity=response.getEntity();
50if(httpEntity!=null){
51//??????????
52System.out.println("result:"+EntityUtils.toString(httpEntity??"UTF-8"));
53}else{
54System.out.println("?????????");
55}
56//??????
57if(closeableHttpClient!=null){
58closeableHttpClient.close();
59}
60}catch(Exceptione){
61e.printStackTrace();
62}
63}
64
65}
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
??????????????????????????Щ?????????????????????????????ν???????????????α???????????????????300??Python?????????y??????????????????????????????y????????y????????????????????????淨(jìng)???????????????????????????????????????????????????????????Python?????????????????????????????????????????????post??????????????????Python+PyCharm????????????????diff???????
???·???
App??С????H5?????????????????Щ??
2024/9/11 15:34:34?????????????????????????
2024/9/10 11:13:49P-One ???????????????????????????????????????
2024/9/10 10:14:12???????????????????????????
2024/9/9 18:04:26??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44

sales@spasvo.com