83

I'm trying to test a simple PHP page using the Chrome extension Postman. When I send URL parameters, the script works fine (eg the variables are available in the $_REQUEST parameter). When I send them as x-www-form-urlencoded parameters, the $_REQUEST parameter only contains the PHPSESSID.

The script:

<?php
var_export($_REQUEST);
?>

When I send URL parameters, $_REQUEST includes them: URL parameters

But when I send them as POST variables, $_REQUEST doesn't include them: enter image description here

What am I missing?

Shahzad Barkati
  • 2,532
  • 6
  • 25
  • 33
whiterook6
  • 3,270
  • 3
  • 34
  • 77
  • 3
    Did you find an answer to this issue? I'm having the same problem. – Stuart Oct 14 '14 at 14:10
  • No, I haven't yet. It might well have been something to do with our API routing, possibly only sending over some of the parameters but not all of them? I'm not sure. – whiterook6 Oct 14 '14 at 21:18
  • Thanks for the response - I've just given up on it just unfortunately... :/ – Stuart Oct 15 '14 at 12:18
  • You say you have some routing, but really, do you? Did you try to just setup a server without any application and put a file like that (so without routing)? Also, I can see you have some headers in your POST request. Did you try removing them? – Kelu Thatsall Feb 05 '15 at 23:34
  • Did you try uninstalling programs that are using network? It might be one of the reason of port conflict – neferpitou Mar 08 '15 at 03:55
  • 4
    I found this answer: http://stackoverflow.com/a/28461500/704803. I was redirecting from HTTP to HTTPS and it was causing the POST variables to be lost. When I told Postman to go directly to the HTTPS url, it worked – andrewtweber Apr 22 '15 at 19:13

13 Answers13

121

I was setting the url in Postman to be http:// but Apache was redirecting to https:// and somehow the POST variables were being dropped along the way.

After I changed it to https://, the POST variables worked properly.

See also: https://stackoverflow.com/a/28461500/704803

Community
  • 1
  • 1
andrewtweber
  • 24,520
  • 22
  • 88
  • 110
  • 4
    This was the issue I had as well. nginx was redirecting via 302 to https and the POST parameters were dropped on the redirect. Manually setting the URL to https:// worked. – anothermh Aug 06 '15 at 19:28
  • I think this is the *bug* in Postman. Working for HTTPS and not Working for HTTP. I have seen there code generated by their functinality `Generate Code` which generated wrong code for Python Requests. querystring = {"username":"data1","mydata":"9232"} payload = "" headers = { 'cache-control': "no-cache", 'postman-token': "aeb70e40-c12a-f713-1d8d-596b8cf976af" } response = requests.request("POST", url, data=payload, headers=headers, params=querystring) print(response.text) I think this is buggy. – Harsh Vardhan Ladha Jun 01 '16 at 01:39
  • I am getting same error but this theory not applying. its not working for both. – Heemanshu Bhalla Apr 11 '19 at 09:13
  • Thanks. This one saved my time. – Rakibul Islam May 14 '20 at 06:43
  • thank you very much, I've been looking for a way to solve this for almost a month – Salz May 10 '22 at 08:27
105

I faced the same issue in PostMan and Advance REST Client both. I checked through fiddler and found that my request payload is not converted into JSON format.

I am passing my data in Body as x-www-form-urlencoded enter image description here

You can fix it by using Content-Type as application/x-www-form-urlencoded in request header. enter image description here

Arvind Dhasmana
  • 1,396
  • 2
  • 9
  • 8
  • 1
    Many thanks @Arvind, changing header to ```application/x-www-form-urlencoded``` actually works! IMHO, this should be accepted as an answer :) – Rafal Gałka Sep 09 '15 at 18:11
  • 2
    Maybe someone is facing the same issue: for me, using `localhost/something` on POSTMAN wasn't working, but after adding `/` to the end, php started getting the values from `POST` and from `php://input`. I had to use `localhost/something/` to make it work. – FirstOne Apr 22 '16 at 02:43
  • 4
    Yes! This fixes the issue. Actually, `PARAMS` field near `URL` sets the `GET` data not `POST` data. And the keyword `PARAMS` is always being related to `GET` and `DATA` being related to `POST` for passing the data. I think peeps at PostMan should fix this to change automatic, or add the `DATA` button automatically. – Harsh Vardhan Ladha Jun 01 '16 at 01:47
  • @FirstOne you should at that as an answer. I got the same problem also – ismailsunni Sep 26 '17 at 14:11
  • @FirstOne - that worked because adding `/` at end avoided a redirect. POSTMAN loses POST parameters on a redirect. – ToolmakerSteve Aug 09 '21 at 14:55
26

Simply use the Body Tab and enter the post parameters there. Note that Body Tab is disabled if Get is selected.

isherwood
  • 58,414
  • 16
  • 114
  • 157
Salman
  • 1,380
  • 7
  • 25
  • 41
14

Check your content-type in the header. I was having issue with this sending raw JSON and my content-type as application/json in the POSTMAN header.

my php was seeing jack all in the request post. It wasn't until i change the content-type to application/x-www-form-urlencoded with the JSON in the RAW textarea and its type as JSON, did my PHP app start to see the post data. not what i expected when deal with raw json but its now working for what i need.

postman POST request

mushcraft
  • 1,994
  • 1
  • 19
  • 27
8

When you send parameters by x-www-form-urlencoded then you need to set header for the request as using Content-Type as application/x-www-form-urlencoded

isherwood
  • 58,414
  • 16
  • 114
  • 157
Satish Shinde
  • 2,878
  • 1
  • 24
  • 41
  • 2
    For me was to select `Body` tab and select `x-www-form-urlencoded` and below that selection you can find key/value entry where you put your POST key/value data. By the way my Postman version is 4.10.4 – Zamrony P. Juhara Mar 25 '17 at 04:37
6

Instead of using raw JSON body, try using form-data.

Form data request

Choxmi
  • 1,584
  • 4
  • 29
  • 47
4

I was having the same problem. To fix it I added the following headers:

Content-Type: application/json

I had to manually add the content type even though I also had the type of "json" in the raw post field parameters.

John O'Connor
  • 5,244
  • 2
  • 24
  • 29
4

Sorry if this is thread Necromancy, but this is still relevant today, especially with how much APIs are used!

An issue I had was: I didn't know that under the 'Key' column you need to put: 'Content-Type'; I thought this was a User Key for when it came back in the request, which it isn't.

So something as simple as that may help you, I think Postman could word that column better, because I didn't even have to read the Documentation when it came to using Fiddler; whereas I did with Postman.

Postman picture

Lee
  • 447
  • 6
  • 9
2

For me, the server was expect HTTPS requests, but I didn't specify that in the URL. The hook would reach the server, but the body would be empty.

user2229618
  • 125
  • 1
  • 11
0

Sometimes Version problem in 'Postman' :

I have face the same problem. While sending the data using the oldest version of postman.
That time I have received the empty json data in server side.
And I have fix this problem, Once I uninstall the oldest version of postman and installed with latest version.

Mohammed Yasin
  • 487
  • 7
  • 12
0

If you are using Laravel Request method add your

Accept:Application/json

to your postman header

enter image description here

Ejeh
  • 425
  • 5
  • 7
0

I came here again after I created an endpoint which also would not find the given POST-parameters. But the problem now was the missing forward slash.. So that's another one to look out for.

Jannick Breunis
  • 195
  • 2
  • 14
-1

I was also facing this issue and I just add www in url like -

https://www.your-domain.com/