httpclient通过传输json格式参数操作页面。


 
 
public class DGMApiTest {
     public static void main(String[] args) throws HttpException, IOException  {
         String url="https://api.dhlecommerce.dhl.com/rest/v2/Tracking";      //一个物流网站示例  
                getHomePage(url);
                
            }
                       
            public static void getHomePage(String url) throws HttpException, IOException {
                DefaultHttpClient client = new DefaultHttpClient(new PoolingClientConnectionManager());
                HttpPost postMethod = new HttpPost(url);
                String json = "{ \"trackItemRequest\": {\"token\": \"32e657a041df15a1bcccffff8cbf61c7\",\"messageLanguage\": \"en\",\"messageVersion\": \"1.1\",\"trackingReferenceNumber\": [\"LW043144320DE\"] } }";
                System.out.println(json);
                postMethod.setHeader("Content-Type", "application/json; charset=utf-8");        
                StringEntity se = new StringEntity(json);
                se.setContentType("text/json");
                postMethod.setEntity(se);
                CloseableHttpResponse response = null;
                response = client.execute(postMethod);
                HttpEntity entity = null;
                entity = response.getEntity();
                String track = EntityUtils.toString(entity, "UTF-8");
                System.out.println(track);                
            }
}
 
 

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM