Jump to content
  • Advertisement
Sign in to follow this  
oblivion_ocean

Binary Data To A Webserver

This topic is 2412 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using winsock to send binary image data to a simple PHP script.

theSocket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);

I can get regular data to send properly but binary data is not working out here and showing up all corrupt.
I was careful not to use any string functions which would corrupt the data on the client end.

Any help would be very much appreciated ..the more detail the better. smile.png

POST url HTTP/1.1
HOST: server
User-Agent: program
Content-Transfer-Encoding: binary
Content-type: application/x-www-form-urlencoded; charset=UTF-8
Content-length: 1723

data=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

$fp = fopen($filename, "wb");
fwrite($fp, $_POST["data"]);
fclose($fp);

Share this post


Link to post
Share on other sites
Advertisement
Content-type: application/x-www-form-urlencoded; charset=UTF-8
This means that your message will contain name/value pairs written in plain text.
N.B. I'm pretty sure that using [font=courier new,courier,monospace]Content-Transfer-Encoding: binary[/font] in conjunction with the above means that you've somehow encoded your binary data into plain-text, such as with base-64, etc...

You probably want to look at using the [font=courier new,courier,monospace]application/octet-stream[/font] mime type instead.

Share this post


Link to post
Share on other sites
Thanks for the reply.

I tried application/octet-stream and the result is empty, with or without binary data.
Perhaps using $_POST is a problem after that or? Really not sure.

Edit: Got it working, just can't use post, grabbed the raw data.

Thanks!

Share this post


Link to post
Share on other sites
In PHP, you don't want to use a "post" parameter for binary data. Instead, you want to PUT the actual, binary, data, and use file_get_contents("php://input").

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!