Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- HTTP POST to send large amounts of data?
March 19, 2006, 12:58 am
rate this thread
I'm new to web programming, and I've been looking all day on the web for
an answer to this question.
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
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.
Thanks for any pointers.
Re: HTTP POST to send large amounts of data?
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
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de /