I'm using android volley StringRequest to send a post request to a PHP file which is already hosted online. This was working before but after the domain name was changed, this PHP file no longer receives the volley request as a post request. In the PHP file $_SERVER['REQUEST_METHOD']
returns GET instead of POST.
Here is the android volley request code snippet
StringRequest request = new StringRequest(Request.Method.POST, postURL, new Response.Listener<String>(){
@Override
public void onResponse(String s) {
Log.d("MY_DEBUG",s);
}
},new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError volleyError) {
}
}) {
@Override
public Map<String, String> getHeaders()
{
Map<String, String> parameters = new HashMap<>();
parameters.put("Connection", "Keep-Alive");
return parameters;
}
@Override
public String getBodyContentType() {
//return "application/x-www-form-urlencoded; charset=UTF-8";
return "application/x-www-form-urlencoded";
}
//adding parameters to send
@Override
protected Map<String, String> getParams() {
Map<String, String> parameters = new HashMap<>();
parameters.put("request", "edit_product");
parameters.put("id", id);
return parameters;
}
};
request.setShouldCache(false);
InitiateVolley.getInstance().addToRequestQueue(request);
And here are the few first lines of code in the PHP file that handles the post request from an android volley
if($_SERVER['REQUEST_METHOD']=='POST'){
//it's a POST request, We are good to go...handle the post request.
}else{
//not a POST request, kill it here
echo "error";
die();
}
What could be causing this issue? Is there a setting I have to do on the PHP side? Or maybe the PHP version of the new domain? Please help out