android中httppost发送的参数在服务器上被作为null插入
我试图使用截取功能将参数发送到服务器,即将数据发送到google云端点,但在服务器上,插入了null值。我在邮递员身上也试过了 如果我使用x-www-form-urlencoded,我在postman和android中都会遇到错误:android中httppost发送的参数在服务器上被作为null插入,android,android-volley,google-cloud-endpoints,Android,Android Volley,Google Cloud Endpoints,我试图使用截取功能将参数发送到服务器,即将数据发送到google云端点,但在服务器上,插入了null值。我在邮递员身上也试过了 如果我使用x-www-form-urlencoded,我在postman和android中都会遇到错误: { "error": { "errors": [ { "domain": "global", "reason": "parseError", "message": "Th
{
"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."
}
}
如果我使用表单数据,我会在邮递员中得到我需要的响应。同样,我使用内容类型作为表单数据。但在服务器的数据库中插入了空值
我的方法是:
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", "prachi@gmail.com");
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);
RequestQueue=Volley.newRequestQueue(MainActivity.this);
//“标签”用于取消请求
String url=“我的url”;
final ProgressDialog pDialog=新建ProgressDialog(MainActivity.this);
pDialog.setMessage(“注册…”);
pDialog.show();
StringRequest mstringrequest=新建StringRequest(Request.Method.DEPRECATED_GET_或_POST、url、new Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
//mPostCommentResponse.requestCompleted();
Log.e(“标签”,“服务--o/p-”+响应);
pDialog.disclose();
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
//mPostCommentResponse.requestEndedWithError(错误);
Log.e(“标签”,“服务--i/p-”+错误);
pDialog.disclose();
}
}) {
@凌驾
受保护的映射getParams(){
Map params=新的HashMap();
参数put(“显示电子邮件”prachi@gmail.com");
参数put(“显示名称”、“普拉奇”);
返回参数;
}
@凌驾
公共映射getHeaders()引发AuthFailureError{
Map params=新的HashMap();
参数put(“内容类型”、“表单数据”);
参数put(“内容处理”、“表单数据”);
返回参数;
}
};
mstringrequest.setRetryPolicy(新的DefaultRetryPolicy(
60000,
DefaultRetryPolicy.DEFAULT\u最大重试次数,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
添加(mstringrequest);
请帮忙。。我错在哪里我找到了解决办法
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);
RequestQueue queue=Volley.newRequestQueue(LoginActivity.this);
final ProgressDialog pDialog=新建ProgressDialog(LoginActivity.this);
设置消息(“登录…”);
pDialog.show();
JsonObjectRequest JSONObjectReq=新的JsonObjectRequest(Request.Method.POST,Constants.URL\u Login,Jsonobj,
新的Response.Listener(){
@凌驾
公共void onResponse(JSONObject响应){
//mPostCommentResponse.requestCompleted();
Log.e(标签“服务--o/p-”+响应);
pDialog.disclose();
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
//mPostCommentResponse.requestEndedWithError(错误);
Log.e(“标签”,“服务--i/p-”+错误);
pDialog.disclose();
}
});
jsonObjReq.setRetryPolicy(新的DefaultRetryPolicy(
60000,
DefaultRetryPolicy.DEFAULT\u最大重试次数,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
add(jsonObjReq);
尝试使用“内容类型”、“应用程序/json”
并发送json
编码数据。我也尝试过。但仍然不起作用:(我们使用的是带有数据存储的Google端点,我们想发送post数据,而不是json encodedOk,我是一个猜测。一个可怕的猜测。