HTTP POST to send large amounts of data?

Discussion in 'HTML' started by Bint, Mar 19, 2006.

  1. Bint

    Bint Guest

    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
    Bint, Mar 19, 2006
    #1
    1. Advertising

  2. 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/
    Benjamin Niemann, Mar 19, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brent
    Replies:
    3
    Views:
    491
    Raymond Lewallen
    Apr 7, 2004
  2. Andersen
    Replies:
    2
    Views:
    382
  3. David
    Replies:
    0
    Views:
    322
    David
    Jun 21, 2006
  4. flamesrock
    Replies:
    2
    Views:
    370
    flamesrock
    Mar 12, 2005
  5. Wayne Marsh

    Handling large amounts of data

    Wayne Marsh, Nov 20, 2004, in forum: C Programming
    Replies:
    3
    Views:
    419
    Malcolm
    Nov 20, 2004
Loading...

Share This Page