简体   繁体   中英

RESTful web service error 500 on android

Hello guys I'm new to restful service. My friend created REST backend with Spring. When I post this URL --> http://smartcar.tobaconsulting.com:9999/api/v1/login with postman or angularjs http.post, it's fine. You guys can check it out in postman by including this body

{ "username":"alvin", "password":"alvin" }

and set content type to JSON (application/json).

But when I code to Android, why it's not working and return 500 error code. My friend said that I'm not including header. I'm using loopj http library http://loopj.com/ . Here is my android code

        RequestParams params = new RequestParams();
        params.put("username", username);
        params.put("password", password);

        AsyncHttpClient client = new AsyncHttpClient();
        client.post("http://smartcar.tobaconsulting.com:9999/api/v1/login", params, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                Log.d(TAG, String.format("status code: %d", statusCode));
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                Log.d(TAG, String.format("status code: %d", statusCode));
            }
        });

Please help me guys. I trying to solve this problem for hours and haven't find any clue. Thanks

i checked your URL no error in server response

Access-Control-Allow-Credentials →true

Access-Control-Allow-Methods →GET, POST, PUT, DELETE

Access-Control-Allow-Origin →chrome-extension://mkhojklkhkdaghjjfdnphfphiaiohkef

Access-Control-Expose-Headers →X-AUTH-TOKEN

Content-Length →0

Date →Thu, 07 Apr 2016 08:35:26 GMT

Server →Apache-Coyote/1.1

X-AUTH-TOKEN →eyJ1c2VybmFtZSI6ImFsdmluIiwiZW1haWwiOiJhbHZpbkBhbHZpbi5jb20iLCJleHBpcmVzIjoxNDYwODgyMTI2MDc4LCJvd25lcmlkIjo2LCJteVJvbGVzIjpbIlVTRVIiLCJBRE1JTiJdfQ==.M9/71trIPbnXxCh7avSWBK42UDXUxWYXZrNOlHhO7iQ=

I would personally suggest using Volley lib for android, there is some useful method inside volley and google strongly recommended that Transmitting Network Data Using Volley

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM