HTTP POST to send large amounts of data?

B

Bint

Hello,
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
"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.

Thanks for any pointers.

B
 
B

Benjamin Niemann

Bint said:
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'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top