마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 loopj AsyncHttpClient 사용해서 http 통신 하고 있는데 post방식으로 파라미터가 넘어가지 않습니다.

0 추천

안녕하세요. http 통신을 하려 하는데 포스트로 했을때 파라미터가 안넘어가네요.

 

private void AsyncLogin(RequestParams params) {
        AsynHttpClient.post(LOGIN_URL, params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                Log.v("TAG", "response : " + response);

                try {
                    String msg = (String) response.get("msg");
                    int code = response.getInt("code");
                    Log.v("test", "msg,code : " + msg + "code" + code);
                    
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                try {
                    Log.e("onFailure: ", "onFailure ---------------------------------------------------------------");
                    Log.e("statusCode : ", String.valueOf(statusCode));
                    Log.e("headers : ", String.valueOf(headers));
                    Log.e("responseString : ", responseString);
                }catch (Exception e) {
                    e.printStackTrace();
                }

            }
        });
    }

다음과 같이 호출을 했는데 파라미터가 안넘겨지다보니 에러가 나네요.

서버는 스프링 자바로 되어있는데, 이게 스프링 기본인지

Postman으로 테스트 시에 "x-www-form-urlencoded"로 선택해서 보낼때만 넘어가지는데

그래서 호출할 때 entity 만들어서 "Content-type" "application/x-www-form-urlencoded"로 추가해서 해보기도 하고

AsyncHttpClient.addHeader("Content-type", "application/x-www-form-urlencoded");도 해보고 했는데

다 안되네요;;

혹시 이런 경험 해보신 분 계신가요?

양꼬양 (2,040 포인트) 님이 2017년 9월 12일 질문

1개의 답변

0 추천
POST를 하는 두가지 타입이 있네요. json이라면 아래 샘플에서 두번째로 처리해야 할 것 같네요.

https://stackoverflow.com/questions/13052036/posting-json-xml-using-android-async-http-loopj
Will Kim (43,170 포인트) 님이 2017년 9월 12일 답변
...