HttpClientTest

public class HttpClientTest {


public static void main(String[] args) throws Exception {
test1();
}


public static void test1() throws Exception {
String url = "http://121.199.26.12:8080/mguid/section/selectAll.do";
HttpClient client = HttpClients.createDefault();

HttpHost target = new HttpHost("121.199.26.12", 8080, "http");
HttpHost proxy = new HttpHost("proxy_host", "port", "http");

RequestConfig config = RequestConfig.custom()
                .setProxy(proxy)
                .build();

HttpGet getMethod = new HttpGet("/mguid/section/selectAll.do");
getMethod.setConfig(config);

// getMethod.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36");
// getMethod.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");

HttpResponse response = client.execute(target, getMethod);
HttpEntity entity = response.getEntity();
// EntityUtils.consume(entity);

String json = EntityUtils.toString(entity);
out.println(response.getStatusLine());
out.println(json);

JSONObject jsonObj = new JSONObject(json);
out.println(jsonObj.get("dataList").getClass().getCanonicalName());

JSONArray arr = jsonObj.getJSONArray("dataList");
out.println(arr.getJSONObject(0).get("showorder"));
}
}

你可能感兴趣的:(HttpClientTest)