Converting a POSTMAN request to Curl
You can see the button "Code" in the attached screenshot, press it and you can get your code in many different languages including PHP cURL
Edited: As other answers said Postman UI was updated, I change the images accordingly
Converting postman request to cURL
Curl's default Content-Type is application/x-www-form-urlencoded so your problem is probably that the data you are POSTing is not actually form data. It might work if you set the content type header properly:
curl -X POST "your_url" -H "Content-Type: text/csv" -F
"csvfile=@sample.csv"
Converting Postman to Curl windows
You need to remove the linebreaks:
curl -L -X POST "https://timingserver.net/api/bridge/generic" -H "cache-control: no-cache" -H "connection: close" -H "content-type: application/json" --data-raw "{ \"username\":\"myusername\", \"password\":\"mypassword\", \"event\":\"demo\", \"checkpoint\":12, \"detections\":[{\"bib\":100, \"dt\":\"2022-01-12T13:09:23.045\"}, {\"bib\":101, \"dt\":\"2022-01-12T13:09:23.045\"}, {\"bib\":102, \"dt\":\"2022-01-12T13:09:23.045\"}, {\"bib\":199, \"dt\":\"2022-01-12T13:10:23.045\"}] }"
Simulate a specific CURL in PostMan
A simpler approach would be:
- Open POSTMAN
- Click on "import" tab on the upper left side.
- Select the Raw Text option and paste your cURL command.
- Hit import and you will have the command in your Postman builder!
- Click Send to post the command
Postman POST request works but doesnt when exported to cURL / request / http.request
cURL is displaying the raw response of the body, while Postman and Firefox process the response. In your case, I suspect that you request a zipped response with a header like Accept-Encoding: gzip, deflate
. If you remove that header, you will get the uncompressed response.
If there is no such header in your request, it would be good to see the request you are trying to execute.
How do I turn this curl request into Postman request
Import the cURL
using Import->Paste Raw Text
.
curl gives 400 error but works in postman?
Setting this request to use a cookie session and sending the username/password in a POST request yields a successful login.
function curl( $url=NULL, $options=NULL, $headers=false ){
$vbh = fopen('php://temp', 'w+');
session_write_close();
/* Initialise curl request object - these should be OK as-is */
$curl=curl_init();
/* Define standard options */
curl_setopt( $curl, CURLOPT_URL, trim( $url ) );
curl_setopt( $curl, CURLOPT_AUTOREFERER, true );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $curl, CURLOPT_FAILONERROR, true );
curl_setopt( $curl, CURLOPT_HEADER, false );
curl_setopt( $curl, CURLINFO_HEADER_OUT, false );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_BINARYTRANSFER, true );
curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 20 );
curl_setopt( $curl, CURLOPT_TIMEOUT, 60 );
curl_setopt( $curl, CURLOPT_USERAGENT, 'Mozilla/5.0' );
curl_setopt( $curl, CURLOPT_MAXREDIRS, 10 );
curl_setopt( $curl, CURLOPT_ENCODING, '' );
/* enhanced debug */
curl_setopt( $curl, CURLOPT_VERBOSE, true );
curl_setopt( $curl, CURLOPT_NOPROGRESS, true );
curl_setopt( $curl, CURLOPT_STDERR, $vbh );
/* Assign runtime parameters as options to override defaults if needed. */
if( isset( $options ) && is_array( $options ) ){
foreach( $options as $param => $value ) curl_setopt( $curl, $param, $value );
}
/* send any headers with the request that are needed */
if( isset( $headers ) && is_array( $headers ) ){
curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers );
}
/* Execute the request and store responses */
$res=(object)array(
'response' => curl_exec( $curl ),
'status' => curl_getinfo( $curl, CURLINFO_RESPONSE_CODE ),
'info' => (object)curl_getinfo( $curl ),
'errors' => curl_error( $curl )
);
rewind( $vbh );
$res->verbose=stream_get_contents( $vbh );
fclose( $vbh );
curl_close( $curl );
return $res;
}
# create a temporary file somewhere to store cookie data.
# Using the system temp directory should mean automatic
# deletion of these files in time.
$cookiestore=tempnam( sys_get_temp_dir(), '_cookiejar_' );
$url='http://armycalling.com/baligaz-api/api/userapi/login';
$headers=array(
'x-api-key: BALIGAZ@123',
'Authorization: Basic YWRtaW46YmFsaWdheiFAIyQ='
);
$args=array(
'email' => 'rasakumar.srk@gmail.com',
'password' => 'rasakumar.srk'
);
/*
Mark the request as a new Cookie session - subsequent requests
would have different options without CURLOPT_COOKIESESSION
*/
$options=array(
CURLOPT_COOKIESESSION => true,
CURLOPT_COOKIEFILE => $cookiestore,
CURLOPT_COOKIEJAR => $cookiestore,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $args
);
/*
Make the request with specified config options
*/
$res=curl( $url, $options, $headers );
/*
If the request is successful a 200 OK status code will be received
so we can then proceed to work with the response data.
If the request fails, using the returned info & verbose properties
of the response will show useful debug info.
*/
if( $res->status==200 ){
printf('<pre>%s</pre>',print_r( $res->response, true ) );
}
This yields:
{
"status": true,
"message": "User login successful.",
"data": {
"id": "22",
"user_id": "baligaz_595689",
"first_name": "Rasa",
"last_name": "Kumar",
"email": "rasakumar.srk@gmail.com",
"password": "529f263ebb230b4709003bb0f7457f90",
"phone": "73339190384",
"profile_img": "http://armycalling.com/baligaz-api/profile_image/baligaz_595689_app_one.png",
"role": "1",
"station_id": "HP Petrols",
"forgot_otp": "",
"created": "2022-06-24 04:47:13",
"created_by": null,
"modified": "2022-06-30 23:38:15",
"updated_by": "baligaz_595689",
"login_completed": null,
"status": "1"
}
}
Related Topics
Why Preg_Replace Throws Me a "Unknown Modifier" Error
PHP Timezone Database Is Corrupt Error
How to Read a .Txt File with PHP
How to Set Short Tag(<) in PHP
Illegal Command Error Code 127 in PHP Exec Function
Opposite of Nl2Br? Is It Str_Replace
Why Can't I Access the Array with Index Directly
How to Make Sure That Values from MySQL Keep Their Type in PHP
PHP Optional Parameters - Specify Parameter Value by Name
How to Send an HTML Email with an Inline Attached Image with PHP
File Download Script Doesn't Work When Called from Ajax
How to I Send Data from JavaScript to PHP and Vice Versa
How to Extract HTML Comments and All HTML Contained by Node
Replace Values in a Uri Query String