By smerny


2016-08-18 00:09:20 8 Comments

I've got Postman (the one that doesn't open in Chrome) and I'm trying to do a POST request using raw json.

In the Body tab I have "raw" selected and "JSON (application/json)" with this body:

{
    "foo": "bar"
}

For the header I have 1, Content-Type: application/json

On the PHP side I'm just doing print_r($_POST); for now, and I'm getting an empty array.


If I use jQuery and do:

$.ajax({
    "type": "POST",
    "url": "/rest/index.php",
    "data": {
        "foo": "bar"
    }
}).done(function (d) {
    console.log(d);
});

I'm getting as expected:

Array
(
    [foo] => bar
)

So why isn't it working with Postman?


Postman screenshots:

enter image description here

and header:

enter image description here

5 comments

@Itachi 2019-01-29 01:09:40

Just check JSON option from the drop down next to binary; when you click raw. This should do

skill synon pass json to postman

@smerny 2019-01-29 07:16:58

this is a fairly old post.. but if you look at the question you'll see that I did exactly that. you may want to read the question, the selected answer, and the comments on the selected answer to understand the problem and solution better.

@Neo 2017-03-29 05:48:44

I was facing the same problem, following code worked for me:

$params = (array) json_decode(file_get_contents('php://input'), TRUE);
print_r($params);

@meda 2016-08-18 00:32:35

Unlike jQuery in order to read raw JSON you will need to decode it in PHP.

print_r(json_decode(file_get_contents("php://input"), true));

php://input is a read-only stream that allows you to read raw data from the request body.

$_POST is form variables, you will need to switch to form radiobutton in postman then use:

foo=bar&foo2=bar2

To post raw json with jquery:

$.ajax({
    "url": "/rest/index.php",
    'data': JSON.stringify({foo:'bar'}),
    'type': 'POST',
    'contentType': 'application/json'
});

@meda 2016-08-18 02:02:50

yes exaclty posting json vs post variables are different

@Jaroslav Štreit 2018-06-28 10:17:02

Install Postman native app, Chrome extension has been deprecated. (Mine was opening in own window but still ran as Chrome app)

@jhpratt 2019-01-01 07:36:22

This doesn't answer the question.

@Jaroslav Štreit 2019-01-02 08:25:27

@jhpratt actually it does. I had same problem. When used Postman app, it worked. Question is: So why isn't it working with Postman?

@CoredusK 2017-04-27 09:22:49

meda's answer is completely legit, but when I copied the code I got an error!

Somewhere in the "php://input" there's an invalid character (maybe one of the quotes?).

When I typed the "php://input" code manually, it worked. Took me a while to figure out!

@Charlie Stanard 2018-08-20 18:24:08

Glad I scrolled down a little further and saw this - I was having the same issue. Good find!

@smerny 2019-02-14 16:19:50

It looks like someone fixed it in an edit to meda's post. But I looked at the edit history and found that the original post had 200c 200b (zero width characters) between the "n" and "p" in "input". Not sure how he ended up with that, but it's fixed now.

Related Questions

Sponsored Content

17 Answered Questions

11 Answered Questions

1 Answered Questions

[SOLVED] POST Request works with Postman, but not with Guzzle

0 Answered Questions

ATG REST service not getting raw POST JSON data from POSTMAN

2 Answered Questions

[SOLVED] how to send object using postman rest client to call REST service

12 Answered Questions

[SOLVED] JavaScript/jQuery to download file via POST with JSON data

1 Answered Questions

[SOLVED] Postman send raw json not working

2 Answered Questions

[SOLVED] Send POST data with raw json with postman Express

1 Answered Questions

[SOLVED] Json object sent by postman received with null members

  • 2016-08-21 09:17:14
  • Yonatan Nir
  • 1420 View
  • 2 Score
  • 1 Answer
  • Tags:   java json postman

2 Answered Questions

[SOLVED] How to send the json data in GET request thru browser/Postman?

Sponsored Content