Re: Reading binary http post

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Manuel Lemos schreef:
Hello,

on 02/21/2006 03:40 PM Dirk Vanden Boer said the following:
I have a C++ application that posts binary data to a php script that I created using libcurl. Everything works fine except when my binary data happens to start with the '&' symbol. In that case I can't read the http post data (isset returns false).

The post argument then looks like data=&ÑÚA
Reading the post is done like this:
if (isset($_POST['data'])
Is there a way to fix this problem?

The problem is that you are misleading PHP telling that you are posting
form data. You need to correct the request Content-Type. It must not be
application/x-www-form-urlencoded nor multipart/form-data . I think you
can use anything except those types, like for instance
application/octet-stream which is the default for binary files.

I don't know how can you hack libcurl to make it use the right request
content-type. It is probably easy. If you are not able to do it, you may
want to try this PHP HTTP client class . It can send custom POST requests.

http://www.phpclasses.org/httpclient


You are correct, setting the headers is necessary but I was already doing that, curl supports it by calling

struct curl_slist *headers=NULL;
headers = curl_slist_append(headers, "Content-Type: text/xml");
curl_easy_setopt(easyhandle, CURLOPT_HTTPHEADER, headers);

I have everything working at the moment by base64 encoding my data and then doing a urlencode. One pitfall I noticed: do not urlencode the post argument, only the data, eg:

data=JtVLV43XWl...

urlencoded
data%3DJtVLV...

This doesn't work, so I just urlencoded my base64 data, and prepended the data= string.


Thanks for all your help guys from this thread ;)

Cheers,

Dirk

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux