안드로이드 6.0이 되면서 더이상 Apache Http를 지원하지 않게 되었다.

이제 HttpURLconnection사용을 권장하고 있다.

그래서 이제 httppost를 사용하려면 다음과 받은 방법을 사용하여서 apache http 를 설치해야한다.


/app/gradle 에 useLibarry 'org.apche.http.legacy'를 추가시킨다.

android {

useLibrary 'org.apache.http.legacy'

그러면 http post를 사용할 수있다.


INTERNET 퍼미션!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
        try {
 
            URI url = new URI(params[0]);
            String data = params[1];
 
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost();
            httpPost.setURI(url);
 
            StringEntity entity = new StringEntity(data, HTTP.UTF_8);
            httpPost.setEntity(entity);
 
            HttpResponse httpResponse = httpClient.execute(httpPost);
 
            responseString = EntityUtils.toString(httpResponse.getEntity(), HTTP.UTF_8);
 
 
 
        } catch (Exception e) {
            e.printStackTrace();
        }
 
        return responseString;
    }
cs


Async를 사용하여 json 형식으로 데이터를 전송하고, 데이터를 받는다.


'Programming > Android' 카테고리의 다른 글

SharedPreferences  (0) 2016.08.24
Context  (0) 2016.08.24
Activity 생명주기  (0) 2016.08.24
Fragment  (0) 2016.08.24
permission  (0) 2016.08.24

+ Recent posts