HttpClient, HttpPost, HttpResponse, HttpEntity 사용하기


HttpCliend

HttpPost

HttpResponse

HttpEntity


NameValuePair


공부해야게따ㅠㅠ



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://localhost:8080/testLatLngData");
httpPost.addHeader("Content-Type""application/x-www-form-urlencoded");
 
List<NameValuePair> testParam = new ArrayList<>();
testParam.add(new BasicNameValuePair("lat", ( "37.469997210138416" )));
testParam.add(new BasicNameValuePair("lng", ( "126.9273415126953" )));
 
httpPost.setEntity(new UrlEncodedFormEntity(testParam, "UTF-8"));
 
HttpResponse resp = httpClient.execute(httpPost);
 
HttpEntity respEntity = resp.getEntity();
 
Object obj = JSONValue.parse(new InputStreamReader(respEntity.getContent()));
 
//결과처리
//JSONObject jsonObject = (JSONObject) obj;
cs


+ Recent posts