Android 将post参数发送到服务器时始终为空
我是Android开发的新手,我面临着一个问题,我通过截击向服务器发送Post参数,但在服务器上我总是收到空值。我无法在下面给出的代码中找到我做错了什么,请帮助 代码如下Android 将post参数发送到服务器时始终为空,android,android-volley,Android,Android Volley,我是Android开发的新手,我面临着一个问题,我通过截击向服务器发送Post参数,但在服务器上我总是收到空值。我无法在下面给出的代码中找到我做错了什么,请帮助 代码如下 String postJsonUrl = "https://example.com/activate_dealer.php"; // Post params to be sent to the server HashMap<String, Strin
String postJsonUrl = "https://example.com/activate_dealer.php";
// Post params to be sent to the server
HashMap<String, String> params = new HashMap<String, String>();
// params.put("token", DeviceToken1);
params.put("full_name", fname);
params.put("mobile", mobile);
params.put("password", pass);
params.put("email", email);
params.put("city", city);
params.put("pincode", pincode);
params.put("address", address);
params.put("sponsor", sponsor);
params.put("parent", parent);
//JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
// url, params, //Not null.
// new Response.Listener<JSONObject>()
JsonObjectRequest req = new JsonObjectRequest(Request.Method.POST,postJsonUrl, new JSONObject(params),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
VolleyLog.v("Response:%n %s", response.toString(4));
String loginStatus = response.getString("Lstatus");
//String pi = response.getString("pi");
//Log.d("nn",nickname);
//Toaster.toast(loginStatus);
String postJsonUrl=”https://example.com/activate_dealer.php";
//将要发送到服务器的Post参数
HashMap params=新的HashMap();
//参数put(“令牌”,DeviceToken1);
参数put(“全名”,fname);
参数put(“移动”,移动);
参数put(“密码”,pass);
参数put(“电子邮件”,电子邮件);
参数put(“城市”,城市);
参数put(“pincode”,pincode);
参数put(“地址”,地址);
参数put(“发起人”,发起人);
参数put(“父”,父);
//JsonObjectRequest JSONObjectReq=新的JsonObjectRequest(Request.Method.POST,
//url,参数,//不为空。
//新的Response.Listener()
JsonObjectRequest req=新JsonObjectRequest(Request.Method.POST、postJsonUrl、新JSONObject(params),
新的Response.Listener(){
@凌驾
公共void onResponse(JSONObject响应){
试一试{
VolleyLog.v(“响应:%n%s”,响应.toString(4));
stringloginstatus=response.getString(“Lstatus”);
//String pi=response.getString(“pi”);
//Log.d(“nn”,昵称);
//烤面包机。烤面包机(loginStatus);
尝试用这种方式发送请求
StringRequest stringRequest = new StringRequest(Request.Method.POST, postJsonUrl,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(MainActivity.this,response,Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this,error.toString(),Toast.LENGTH_LONG).show();
}
}){
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
params.put("full_name", fname);
params.put("mobile", mobile);
params.put("password", pass);
params.put("email", email);
params.put("city", city);
params.put("pincode", pincode);
params.put("address", address);
params.put("sponsor", sponsor);
params.put("parent", parent);
return params;
}
};
getRequestOtpPage().addToRequestQueue(stringRequest);return params;
}
};
getRequestOtpPage().addToRequestQueue(stringRequest);
StringRequest StringRequest=新的StringRequest(Request.Method.POST、postJsonUrl、,
新的Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
Toast.makeText(MainActivity.this,response,Toast.LENGTH_LONG.show();
}
},
新的Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
Toast.makeText(MainActivity.this,error.toString(),Toast.LENGTH_LONG.show();
}
}){
@凌驾
受保护的映射getParams(){
Map params=新的HashMap();
参数put(“全名”,fname);
参数put(“移动”,移动);
参数put(“密码”,pass);
参数put(“电子邮件”,电子邮件);
参数put(“城市”,城市);
参数put(“pincode”,pincode);
参数put(“地址”,地址);
参数put(“发起人”,发起人);
参数put(“父”,父);
返回参数;
}
};
getRequestOtpPage().addToRequestQueue(stringRequest);返回参数;
}
};
GetRequestOtpage().addToRequestQueue(stringRequest);
我必须检索JSON对象而不是$\u POST,这解决了我的问题
$\u POST=json\u解码(文件\u获取\u内容('php://input“),true);编写代码,这样我们就可以看到代码中的错误您的请求接受表单数据或json请求IT接受表单数据您发送的json请求谢谢米兰,$\u POST=json\u decode(file\u get\u contents($)php://input这就解决了我的问题