[PHP] Re: Reading binary http post

2006-02-23 Thread Manuel Lemos
Hello,

on 02/23/2006 02:55 PM Dirk Vanden Boer said the following:
>> 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);

Maybe you think you are doing that correctly but in fact that may not be
accurate.

If you are sure that the content type of the request being sent is
text/xml and PHP is treating as a form post, you should report that as a
PHP bug because PHP should only process form requests when the content
type specifies that.

For binary posts, the way to retrive posted data is not via $_POST.
There are other request variables for that.

-- 

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

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



[PHP] Re: Reading binary http post

2006-02-23 Thread Dirk Vanden Boer

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



[PHP] Re: Reading binary http post

2006-02-22 Thread Manuel Lemos
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

-- 

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

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



[PHP] Re: Reading binary http post

2006-02-21 Thread Cristian MARIN
This is actually not a solution as is not solving Dirk's problem. The 
'A' will make the isset($_POST['data']) to be always true. Another thing 
is that the $_POST['data'] is still not  containing the binary code that 
is expected as the PHP will get the & and will start a new variable


A solution will be the base64_encode() which is the safest way to 
transport binary data over the net.
Another one will be a simple rawurlencode() which is supposed to solve 
exactly this problem and on the server you shouldn't do any decode 
after. However I can't grant you that your binary will correctly survive.





Cristian MARIN - [EMAIL PROTECTED] 


Developer Designers Department
InterAKT Online (www.interaktonline.com 


Dan Baker wrote:
"Dirk Vanden Boer" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
  

Hi,

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?



A quick-n-dirty method is to prepend a known letter to the data, like an 
"A":

data=A&ÑÚA
Then, ignore the first character of the data, since it is known to be the 
"A" character.


I would think that if the data contains an "&" in the middle of the data, 
you may not be getting all the data.

"data=ABC&xyz=123"
$_POST['data'] = "ABC"
$_POST['xyz'] = "123"

DanB
  


[PHP] Re: Reading binary http post

2006-02-21 Thread Dan Baker
"Dirk Vanden Boer" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi,
>
> 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?

A quick-n-dirty method is to prepend a known letter to the data, like an 
"A":
data=A&ÑÚA
Then, ignore the first character of the data, since it is known to be the 
"A" character.

I would think that if the data contains an "&" in the middle of the data, 
you may not be getting all the data.
"data=ABC&xyz=123"
$_POST['data'] = "ABC"
$_POST['xyz'] = "123"

DanB

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