Java 使用截击和接收错误的自定义post请求
这是我的Java 使用截击和接收错误的自定义post请求,java,php,android,Java,Php,Android,这是我的CustomRequest代码。我正在使用Map将参数传递给post Map<String, String> params = new HashMap<String, String>(); params.put("name", username); params.put("buildingname", userbuildingname); params.put("area", userarea); params.put("city"
CustomRequest
代码。我正在使用Map将参数传递给post
Map<String, String> params = new HashMap<String, String>();
params.put("name", username);
params.put("buildingname", userbuildingname);
params.put("area", userarea);
params.put("city", usercity);
params.put("mobileno", usermobileno);
params.put("email", useremail);
params.put("confirmpassword", userconfirmpassword);
params.put("method", method);
params.put("format", format);
CustomRequest jsonObjReq = new CustomRequest(Request.Method.POST, url, params, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
JSONObject resp = response;
abc = resp.toString();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
abc = error.getMessage();
Log.d(TAG, "Error: " + error.getMessage());
}
});
AppController.getInstance().addToRequestQueue(jsonObjReq);
反应就这样过去了
$json_response = json_encode($api_response);
// Deliver formatted data
echo $json_response;
但它给了我一个错误
com.android.volley.AuthFailureError
请帮助终于找到了答案
JSONObject params = new JSONObject();
try {
params.put("method", method);
params.put("format", format);
params.put("name", username);
params.put("buildingname", userbuildingname);
params.put("area", userarea);
params.put("city", usercity);
params.put("mobileno", usermobileno);
params.put("email", useremail);
params.put("confirmpassword", userconfirmpassword);
} catch (Exception e) {
}
JsonObjectRequest req = new JsonObjectRequest(Request.Method.POST, URL, params,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
VolleyLog.v("Response:%n %s", response.toString());
SignUp signUp = new SignUp();
try {
returnResponse(response.getString("saveUsersDetailsResponse"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.e("Error: ", error.getMessage());
}
}
);
AppController.getInstance().addToRequestQueue(req);
我们通过解码json获得所有数据
$json_response = json_encode($api_response);
// Deliver formatted data
echo $json_response;
JSONObject params = new JSONObject();
try {
params.put("method", method);
params.put("format", format);
params.put("name", username);
params.put("buildingname", userbuildingname);
params.put("area", userarea);
params.put("city", usercity);
params.put("mobileno", usermobileno);
params.put("email", useremail);
params.put("confirmpassword", userconfirmpassword);
} catch (Exception e) {
}
JsonObjectRequest req = new JsonObjectRequest(Request.Method.POST, URL, params,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
VolleyLog.v("Response:%n %s", response.toString());
SignUp signUp = new SignUp();
try {
returnResponse(response.getString("saveUsersDetailsResponse"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.e("Error: ", error.getMessage());
}
}
);
AppController.getInstance().addToRequestQueue(req);
$checkmethod = $_SERVER['REQUEST_METHOD'];
$var = file_get_contents("php://input");
$string = json_decode($var, TRUE);
$method = $string['method'];
$name = $string['name'];
$email = $string['email'];
$mobileno = $string['mobileno'];