Question about binary transfers in POST requests [message #172272] |
Tue, 08 February 2011 22:18 |
Anthony Papillion
Messages: 1 Registered: February 2011
Karma: 0
|
Junior Member |
|
|
Hello Everyone,
I'm accessing an API that tells me I need to send the following information as part of a POST request:
username
password
media
Username and password are obviously passed via a url like &username=$username or whatever but media is confusing me. It needs to be the BINARY content of a media file. I'm using cURL to do the transfer and I suspect I'm going to use some setting like CURLOPT_BINARYTRANSFER but I'm not sure how to do it.
Can anyone clue me in?
Thanks!
Anthony
|
|
|
Re: Question about binary transfers in POST requests [message #172282 is a reply to message #172272] |
Wed, 09 February 2011 03:54 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 2/8/2011 5:18 PM, Anthony Papillion wrote:
> Hello Everyone,
>
> I'm accessing an API that tells me I need to send the following
> information as part of a POST request:
>
> username
> password
> media
>
> Username and password are obviously passed via a url
> like&username=$username or whatever but media is confusing me. It
> needs to be the BINARY content of a media file. I'm using cURL to
> do the transfer and I suspect I'm going to use some setting like
> CURLOPT_BINARYTRANSFER but I'm not sure how to do it.
>
> Can anyone clue me in?
>
> Thanks!
> Anthony
Passing in the URL is for a GET request. For a POST request they need
to be passed as POST parameters.
And yes, to retrieve binary data you need to use CURLOPT_BINARYTRANSFER
(see curl_setopt). But other than that I'm not sure what your question is.
What have you tried?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|
Re: Question about binary transfers in POST requests [message #172286 is a reply to message #172272] |
Wed, 09 February 2011 07:06 |
Felix Saphir
Messages: 8 Registered: December 2010
Karma: 0
|
Junior Member |
|
|
Anthony Papillion <papillion(at)gmail(dot)com> wrote:
>
> I'm accessing an API that tells me I need to send the following
> information as part of a POST request:
>
> username
> password
> media
>
> Username and password are obviously passed via a url like
> &username=$username or whatever but media is confusing me. It
> needs to be the BINARY content of a media file. I'm using cURL
> to do the transfer and I suspect I'm going to use some setting
> like CURLOPT_BINARYTRANSFER but I'm not sure how to do it.
There's no need for CURLOPT_BINARYTRANSFER. The trick is to
prepend the filename with '@' like this:
$postdata = array(
'username' => $username,
'password' => $password,
'media' => "@$file['tmp_name']",
);
You then add your data to the cURL request:
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
It's all in the manual btw ...
Felix
|
|
|