简体   繁体   中英

500 exception while connecting to live server using Volley in android

I'm trying to connect to live server using volley authentication and sending values through POST method. It worked well when connected to local server but I'm getting the below exception when connecting to live server.

BasicNetwork.performRequest: Unexpected response code 500 for "URL"

And server side error is below

Error parsing media type 'application/json; charset=utf-8, application/x-www-form-urlencoded; charset=UTF-8' Expected separator ';' instead of ',' This is the error getting in server side

Here is my code

public void userLogin(){
    showDialog(DIALOG_LOADING);

    final String json = new Gson().toJson(arr);

    StringRequest jsonObjReq = new StringRequest(Request.Method.POST,
            Const.URL_LOGIN,
            new Response.Listener<String>() {

                @Override
                public void onResponse(String response) {
                    System.out.println("LOGIN Response :" + response);

                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            NetworkResponse networkResponse = error.networkResponse;
            System.out.println("NetworkResponse "+ networkResponse);
            if (networkResponse!= null && networkResponse.statusCode == 401) {
                Login.this.runOnUiThread(new Runnable() {
                    public void run() {
                        invalidemail.setVisibility(View.GONE);
                        inactiveaccount.setVisibility(View.VISIBLE);
                    }
                });

            }
            error.printStackTrace();
            removeDialog(DIALOG_LOADING);
            toast_tv.setText("There is no Internet connection. Try again...!");
            toast.show();
        }
    }){

        @Override
        public byte[] getBody() {
            try {
                return json == null ? null : json.getBytes("utf-8");
            } catch (UnsupportedEncodingException uee) {
                VolleyLog.wtf("Unsupported Encoding while trying to get the bytes of %s using %s",
                        json, "utf-8");
                return null;
            }
        }

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<String, String>();

            String credentials = String.format("%s:%s",Const.auth_username,Const.auth_password);
            String auth = "Basic "
                    + Base64.encodeToString(credentials.getBytes(),
                    Base64.NO_WRAP);
            headers.put("Authorization", auth);
            headers.put("Content-Type", "application/json; charset=utf-8");

            return headers ;
        }
    };

    jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(20 * DefaultRetryPolicy.DEFAULT_TIMEOUT_MS, 0, 0));
    Volley.newRequestQueue(this).add(jsonObjReq);
}

On the server side Jersey is being used with Java.

Finally I fixed the issue.. Actually nothing wrong in code but the volley version which i used was deprecated. When updating the volley library it worked for me.

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