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); } }