Jetty - 9 FREE REQUEST ERROR with Volley server

I updated my dropwizard to 0.8 which uses Jetty -9 server. I am using volley server 1.0.15 to send my JSON request from my application. My problem is that when I send JSON from the volleyball api throws 400, when I send the same request from the postman, it works fine.

WARN [2015-05-08 14: 16: 18,223] org.eclipse.jetty.http.HttpParser: Invalid character 0x16 in state = START for buffer HeapByteBuffer @ 642bbd0f [p = 1, l = 78, c = 8192, r = 77] = {\ x16 <<<\ x03 \ x00 \ x00I \ x01 \ x00 \ x00E \ x03 \ x00 \ xBfE \ x8e \ x82 \ XCB \ XE3 \ XCA ... \ X07 \ xC0 \ x11 \ x00 / \ X005 \ x00 \ x05 \ x00 \ xFfV \ x00 \ x01 \ x00 →> - 1 \ r \ nContent-Lengt ... \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00} WARN [2015-05-08 14: 16: 18,223] org.eclipse.jetty.http.HttpParser: badMessage: 400 Invalid character 0x16 for HttpChannelOverHttp @ 650d154b {r = 0, c = false , a = IDLE, uri = -}

and my code for requesting volleyball

JSONObject userDetails = new JSONObject();
userDetails.put("email", "tasneem");
userDetails.put("password", "1234");
userDetails.put("deviceId", "243243");
userDetails.put("version", "4.4.4");
userDetails.put("platform", "Android");
JsonObjectRequest loginRequest = new JsonObjectRequest(Request.Method.POST,     Constants.URL_LOGIN, userDetails, new Response.Listener<JSONObject>() {
  @Override
  public void onResponse(JSONObject jsonObject) {

  }
}, new Response.ErrorListener() {
  @Override
  public void onErrorResponse(VolleyError volleyError) {
    Log.e(TAG, volleyError.toString());
    mListener.onError(volleyError);
  }
}) {
  @Override
  public Map<String, String> getHeaders() throws AuthFailureError {
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/json; charset=utf-8");
    return headers;
  }
};

      

Sincerely appreciate your help. Thank.

And can anyone tell me how to track the full request without creating a custom volleyball request, is there a way?

+3


source to share


1 answer


I traced the packets sent in wireshark and found that it Content-Type

was mentioned twice in the header .

Content-Type: application/json; charset=utf-8\r\n
Content-Type: application/json; charset=utf-8\r\n
User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.4.2; HTC Desire 526GPLUS dual sim Build/KOT49H)\r\n
.
. 
.

      

Removing the overriden getHeaders () method



@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers;
}

      

Strike>

No override is needed because in com.android.volley.toolbox.JsonRequest.java

, is Content-Type

already set application/json; charset=utf-8

, and it seems that dropwizard 0.8 does not accept the same header twice.

+1


source







All Articles