2016-11-30 66 views
1

我想使用排列向服务器发送参数,即向云端点发送数据,但在服务器上,插入空值。我试过邮递员一样,在android中由httppost发送的参数在服务器上被插入为空

如果我使用的X WWW的形式,进行了urlencoded,我得到错误的邮递员,以及在Android作为:

{ 
"error": { 
    "errors": [ 
     { 
      "domain": "global", 
      "reason": "parseError", 
      "message": "This API does not support parsing form-encoded input." 
     } 
    ], 
    "code": 400, 
    "message": "This API does not support parsing form-encoded input." 
} 

}

如果我用形式数据,我得到了我在邮递员所需要的东西。同样,我使用Content-Type作为表单数据。但空值被插入到服务器的数据库中。

我的方法是:

RequestQueue queue = Volley.newRequestQueue(MainActivity.this); 
    // "TAG" used to cancel the request 
    String url = "My URL"; 

    final ProgressDialog pDialog = new ProgressDialog(MainActivity.this); 
    pDialog.setMessage("Registering..."); 
    pDialog.show(); 

    StringRequest mstringrequest = new StringRequest(Request.Method.DEPRECATED_GET_OR_POST, url, new Response.Listener<String>() { 
     @Override 
     public void onResponse(String response) { 
      // mPostCommentResponse.requestCompleted(); 
      Log.e("TAG", "Service--o/p-" + response); 
      pDialog.dismiss(); 
     } 
    }, new Response.ErrorListener() { 
     @Override 
     public void onErrorResponse(VolleyError error) { 
      // mPostCommentResponse.requestEndedWithError(error); 
      Log.e("TAG", "Service--i/p-" + error); 
      pDialog.dismiss(); 
     } 
    }) { 
     @Override 
     protected Map<String, String> getParams() { 
      Map<String, String> params = new HashMap<String, String>(); 
      params.put("displayEmail", "[email protected]"); 
      params.put("displayName", "prachi"); 
      return params; 
     } 

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


      params.put("Content-Type", "form-data"); 
      params.put("Content-Disposition", "form-data"); 


      return params; 
     } 
    }; 

    mstringrequest.setRetryPolicy(new DefaultRetryPolicy(
      60000, 
      DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
      DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); 


    queue.add(mstringrequest); 

请帮助..我哪里错了

+0

用' “内容类型” 尝试,“应用/ JSON “'并发送'JSON'编码数据。 – mallaudin

+0

我也试过了。但仍然没有工作:( –

+0

我们使用Google Endpoints和Data store,并且我们想发送不是json编码的post数据 –

回答

1

我得到了解决

RequestQueue queue = Volley.newRequestQueue(LoginActivity.this); 
    final ProgressDialog pDialog = new ProgressDialog(LoginActivity.this); 
pDialog.setMessage("Logging In..."); 
    pDialog.show(); 

    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST, Constants.URL_Login, Jsonobj, 
      new Response.Listener<JSONObject>() { 
       @Override 
       public void onResponse(JSONObject response) { 
        // mPostCommentResponse.requestCompleted(); 
        Log.e(TAG, "Service--o/p-" + response); 
        pDialog.dismiss(); 
       } 
      }, new Response.ErrorListener() { 
     @Override 
     public void onErrorResponse(VolleyError error) { 
      // mPostCommentResponse.requestEndedWithError(error); 
      Log.e("TAG", "Service--i/p-" + error); 
      pDialog.dismiss(); 

     } 
    }); 
    jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(
      60000, 
      DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
      DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); 


    queue.add(jsonObjReq); 
相关问题