Send POST data via raw JSON with Postman
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'
});
How to Send file and data via raw JSON from Postman
Here is an example using @ModelAttribute
:
DTO
Controller
Postman UI
Postman: POST request of nested JSON via form-data not working (while via raw-data ok)
I managed to make it work! (note: I added some additional fields compared to the screenshot in question. See below for details:
Why simple json request body in Postman is not working
You have copied the json body from browser or other non standard text editor so the asci character for "," is not the actually one. it got resolved into something else . Just delete it and replace that comma and double quotes with correct correctors.
{
"message":"hi",
"tg_chat_id": "5"
}
Also in postman you can press ctrl+b to format and remove space , (that's not the reason for error though)
Send POST data with raw json with postman Express
It seems like you're passing an invalid value to res.JSON(). Try:
return res.json(data);
Postman send both data in json and image
To send image and data using Postman you have to use form-data content type.
Select body => form-data. Column key has a selector. For a file select file-type and select file. To send data in the same time you will have to separate your json in key value pair.
And remove [FromBody] attribute from the action. It is only used for Content-Type: application/json, but yours Content-Type: multipart/form-data;
How to upload a file and JSON data in Postman?
In postman, set method type to POST.
Then select
Body -> form-data -> Enter your parameter name (file according to your code)
On the right side of the Key field, while hovering your mouse over it, there is a dropdown menu to select between Text/File. Select File, then a "Select Files" button will appear in the Value field.
For rest of "text" based parameters, you can post it like normally you do with postman. Just enter parameter name and select "text" from that right side dropdown menu and enter any value for it, hit send button. Your controller method should get called.
How to send post request to the below post method using postman rest client
- Open
Postman
. - Enter URL in the URL bar
http://{server:port}/json/metallica/post
. - Click
Headers
button and enterContent-Type
as header andapplication/json
in value. - Select
POST
from the dropdown next to the URL text box. - Select
raw
from the buttons available below URL text box. - Select
JSON
from the following dropdown. In the textarea available below, post your request object:
{
"title" : "test title",
"singer" : "some singer"
}Hit
Send
.Refer to screenshot below:
Related Topics
Need Guidance to Start with Zend Acl
Check for Session Timeout in Laravel
Sort Array by Length and Then Alphabetically
How to Properly Display Chinese Characters in PHP
Is There a Function to Make a Copy of a PHP Array to Another
Problems with Lib-Icu Dependency When Installing Symfony 2.3.X via Composer
Using Comparison Operators in a PHP 'Switch' Statement
How to Convert the Time from Am/Pm to 24 Hour Format in PHP
Strange Behavior When Overriding Private Methods
How Add Custom Validation Rules When Using Form Request Validation in Laravel 5
Why Are Escape Characters Being Added to the Value of the Hidden Input
Use Curl with Sni (Server Name Indication)
How to Create a Logfile in PHP
Tracking Email with PHP and Image
How to Trigger Xdebug Profiler for a Command Line PHP Script