1. 程式人生 > >以json為body傳送get請求

以json為body傳送get請求

String url="http://61.161.211.134:9011/tsp/cherry?";
CloseableHttpClient httpclient = null;
httpclient = HttpClients.createDefault();
JSONObject header = new JSONObject();
header.put("fv","0201");
header.put("rs","7");
header.put("v","1.0");
header.put("fn","GW.ECALL.GET_LOCATION");
JSONObject body = new JSONObject();
body.put("woNoOutside","woNoOutside");
body.put("vin","vin");
body.put("msisdn","msisdn");
JSONObject p=new JSONObject();
p.put("header",header);
p.put("body",body);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("p", p.toString()));
String url1 = url+"" + URLEncodedUtils.format(params, HTTP.UTF_8);
HttpGet get = new HttpGet(url1);
CloseableHttpResponse response = httpclient.execute(get);
HttpEntity entity1 = response.getEntity();
String result = EntityUtils.toString(entity1);
response.close();
System.out.println(":"+result);