简体   繁体   English

在Android中使用Volley连接到实时服务器时出现500异常

[英]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. 我正在尝试使用齐射身份验证连接到实时服务器,并通过POST方法发送值。 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" BasicNetwork.performRequest:“ URL”的意外响应代码500

And server side error is below 和服务器端错误如下

Error parsing media type 'application/json; 解析媒体类型'application / json;时出错; charset=utf-8, application/x-www-form-urlencoded; charset = utf-8,应用程序/ x-www-form-urlencoded; charset=UTF-8' Expected separator ';' charset = UTF-8'预期的分隔符';' 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. 在服务器端,Jersey正在与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. 更新排球库对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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