2017-09-15 108 views
1

我知道它的重复的问题,但没有得到他们的任何帮助,所以我问在这里, 这些是我registeruser方法:凌空错误代码400发生

private void registerUser(final String name, final String phone_email, final String password) throws JSONException { 
    Log.d(TAG,name +" "+ phone_email +" "+ password); 
    // Tag used to cancel the request 
    String tag_string_req = "req_register"; 

    pDialog.setMessage("Registering ..."); 
    showDialog(); 

    JSONObject jobj= new JSONObject(); 
    try { 
      jobj.put("name", name); 
      jobj.put("email ", phone_email); 
      jobj.put("password", password); 
    }catch (JSONException e) { 
     e.printStackTrace(); 
    } 

    JsonObjectRequest jsonReq = new JsonObjectRequest(Request.Method.POST,AppConfig.URL_SEND_OTP, 
    jobj, new Response.Listener<JSONObject>() { 
     @Override 
     public void onResponse(JSONObject response) { 
      Log.d(TAG, response.toString() + "Registration responce"); 
      hideDialog(); 
      Intent otp = new Intent(getApplicationContext(), 
             OTPActivity.class); 
      otp.putExtra("name",user_name); 
      otp.putExtra("phone",user_phone_email); 
      startActivity(otp); 
     } 
    }, new Response.ErrorListener() { 
     @Override 
     public void onErrorResponse(VolleyError error) { 
      VolleyLog.d(TAG, "Error: " + error.getMessage()); 
      hideDialog(); 
     } 
    }) { 
     @Override 
     public Map<String, String> getHeaders() throws AuthFailureError { 
      HashMap<String, String> headers = new HashMap<String, String>(); 
      headers.put("Content-Type", "application/json; charset=utf-8"); 
      return headers; 
     } 
    }; 
    // Adding request to request queue 
    Log.e("responce string",jsonReq.toString()); 
    AppController.getInstance(this).addToRequestQueue(jsonReq,tag_string_req); 
} 

我凌空错误400,不知道有什么问题,基本上是关于content-type的错误,但正如我提到我的请求`内容类型和它以前的工作我做了服务器端的变化,并且API在postman bt中工作有问题在这里。

我的堆栈跟踪:

09-15 12:49:33.767 22856-22856/com.wowoni.bikesharing.bicyclesharing D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{6ae5f97 V.E...... R.....I. 0,0-0,0} 
09-15 12:49:33.797 22856-22856/com.wowoni.bikesharing.bicyclesharing E/responce string: [ ] http://192.168.43.187:8085/send-otp 0x37295400 NORMAL null 
09-15 12:49:33.857 22856-24436/com.wowoni.bikesharing.bicyclesharing I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
09-15 12:49:33.857 22856-24436/com.wowoni.bikesharing.bicyclesharing I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
09-15 12:49:33.867 22856-24436/com.wowoni.bikesharing.bicyclesharing I/qtaguid: Tagging socket 49 with tag 3729540000000000{925455360,0} uid -1, pid: 22856, getuid(): 10443 
09-15 12:49:33.887 22856-23046/com.wowoni.bikesharing.bicyclesharing D/mali_winsys: new_window_surface returns 0x3000, [796x360]-format:1 
09-15 12:49:33.977 22856-22856/com.wowoni.bikesharing.bicyclesharing D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1 
09-15 12:49:36.377 22856-24436/com.wowoni.bikesharing.bicyclesharing I/qtaguid: Untagging socket 49 
09-15 12:49:36.377 22856-24436/com.wowoni.bikesharing.bicyclesharing I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
09-15 12:49:36.377 22856-24436/com.wowoni.bikesharing.bicyclesharing I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
09-15 12:49:36.387 22856-24436/com.wowoni.bikesharing.bicyclesharing I/qtaguid: Tagging socket 49 with tag 3729540000000000{925455360,0} uid -1, pid: 22856, getuid(): 10443 
09-15 12:49:36.777 22856-24436/com.wowoni.bikesharing.bicyclesharing I/qtaguid: Untagging socket 49 
09-15 12:49:36.787 22856-24436/com.wowoni.bikesharing.bicyclesharing E/Volley: [59688] BasicNetwork.performRequest: Unexpected response code 400 for http://192.168.43.187:8085/send-otp 
09-15 12:49:36.797 22856-22856/com.wowoni.bikesharing.bicyclesharing D/Volley: [1] 2.onErrorResponse: RegistorActivity 
09-15 12:49:36.807 22856-22856/com.wowoni.bikesharing.bicyclesharing D/ViewRootImpl: #3 mView = null 
09-15 12:49:36.827 22856-22856/com.wowoni.bikesharing.bicyclesharing E/ViewRootImpl: sendUserActionEvent() mView == null 
09-15 12:49:39.277 22856-22856/com.wowoni.bikesharing.bicyclesharing D/ViewRootImpl: ViewPostImeInputStage processPointer 0 
09-15 12:49:39.427 22856-22856/com.wowoni.bikesharing.bicyclesharing D/ViewRootImpl: ViewPostImeInputStage processPointer 1 
+0

你可以发布你的堆栈跟踪吗? – hsm59

+0

我添加了堆栈跟踪。 –

+0

尝试重写“parseNetworkResponse(NetworkResponse响应)”以查看您的原始响应(也许它可以帮助你) –

回答

0

凌空有jsonObjectRequest没有太大的舒适。一次请尝试与Retrofit。它一定会解决您的问题。我也有这个问题,通过Retrofit解决。

+0

感谢您的建议bt我不知道api,并知道完全是耗时我想快速修复,所以如果任何人都可以帮助它,那对我来说会很棒。 –

+0

请别人帮我吗? –

+0

确保它不允许在Web服务中使用GET方法。 –