PHP cURL: how to set body to binary data?
You can just set your body in CURLOPT_POSTFIELDS
.
Example:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://url/url/url" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, "body goes here" );
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));
$result=curl_exec ($ch);
Taken from here
Of course, set your own header type, and just do file_get_contents('/path/to/file')
for body.
PHP - POST request with binary body data - Works with CURL, but not with Laravel
I would try withBody
$post = Http::withBody(file_get_contents($pathToFile), 'image/jpeg')
->withToken("<Token>")
->post($url);
How does one POST a binary file stored locally using php-curl?
you'd use
curl_setopt($curl_handle, CURLOPT_POST, TRUE);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, array('file' => '@foo.ext'));
plus whatever options you need. Relevant docs here: http://php.net/curl_setopt
Related Topics
Laravel Form Methods VS Traditional Coding
Adding Additional Persist Calls to Preupdate Call in Symfony 2.1
How to Convert a Huge Integer to Hex in PHP
Parse Error: Syntax Error, Unexpected '.', Expecting ',' or ';'
PHP for ; Foreach Variable Scope
Why Composer Can Not Find My Brand New Package on Packagist.Org
What Is the Best PHP Dom 2 Array Function
PHP Mail() Works from Command Line But Not Apache
Converting to Date in PHP from Yyyymmdd Format
PHP Session Id Changing on Every Request
Why Is the Semicolon Optional in the Last Statement in PHP
Laravel 5.1 Date_Format Validation Allow Two Formats