You are here: Re: HTTP POST to send large amounts of data? « HTML « IT news, forums, messages
Re: HTTP POST to send large amounts of data?

Posted by Benjamin Niemann on 03/19/06 16:11

Bint wrote:

> I'm trying to send some binary data, a relatively large amount (~128K), to
> a
> PHP script from a wireless device that has TCP/IP sockets. So I'm sending
> all of my data manually (ie ,"POST http://www.blah.com/process.php
> HTTP/1.0\n" as my first string).
>
> I am able to send regular form data such as
> "tireqty=3&oilqty=4&sparkqty=1&address=4204MainStreet\n\n";
> To do this I have a header for the content type like so: "Content-Type:
> application/x-www-form-urlencoded\n";" I can get a php script to receive
> this and interpret the variables correctly. But when I try to do
> something similar with a bunch of binary data, I can't get it to work.
>
> I have even encoded my data in base64 so that it is ready to send as
> ASCII. This data is broken into chunks where after each 76 characters
> there is a
> \r\n line break. I read that I needed to do that.
>
> But HOW do I send it? If I send it as form data, with variables, then it
> only receives the data up until the first line break. I tried changing
> the content type to "Content-Type: application/octet-stream\n", thinking
> that I could just send the data without form variables, but then how do
> you access
> that from PHP? For example I tried sending the string "data=XXXYYY" where
> XXXYYY is my base64 encoded data, but it didn't work.
>
> I can't seem to find any good documentation about this. Which
> Content-Type
> shouldI be using? Can I use octet-streams and still have the data
> connected
> to php variables? It's very confusing.

PHP supports 'application/x-www-form-urlencoded' and 'multipart/form-data'
and will populate $_POST for these content-types.

Use 'multipart/form-data' for large data files. Your data must be properly
encoded - depending of the language which you are using on the client-side,
there might be ready to use code for this.

I think there is also direct access to the POSTed data in PHP (I'm not much
into PHP anymore, but '$fp = fopen("php://input", "r");' might do it..).
You could then send the binary file as-is with content-type
'application/octet-stream'.


--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de/

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация