Re: Reading binary http post
| From: | Dirk Vanden Boer | Date: | Thu, 23 Feb 2006 17:55:30 +0000 |
| Subject: | Re: Reading binary http post | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-230971@lists.php.net to get a copy of this message | ||
Manuel Lemos schreef:
Hello, on 02/21/2006 03:40 PM Dirk Vanden Boer said the following: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, DirkI 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