0

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

10
  • try checking it with some REST tool, Postman for example Commented Mar 7, 2019 at 7:22
  • @VladyslavMatviienko, Postman still sees it as a GET request. I just tried it now Commented Mar 7, 2019 at 7:36
  • Try removing getBodyContentType() method and getHeaders() method. Commented Mar 7, 2019 at 7:48
  • then as you can see, it does not relate to Android. Try logging $_SERVER['REQUEST_METHOD'] value on the PHP side, for example return it instead of ``error` in else Commented Mar 7, 2019 at 7:54
  • @VladyslavMatviienko, $_SERVER['REQUEST_METHOD'] returned GET. I used Postman to check Commented Mar 7, 2019 at 9:35

1 Answer 1

1

I removed the "www" from the url and it solved my problem. This SO question POST Requests seen as GET by server helped

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.