QA.TechInterviews.com - your tech questions answered
Can Someone Give Me An Example Of A HTTP POST Request?
I'm trying to post form data to an external site using PHP. The request currently looks like this:

(ignore the spaces in some of the words - I added them to prevent Yahoo from truncating them)

POST /system.aspx HTTP 1.0
Host: thesitetosendto.com
Cookie: username=myusername&pass word=mypassword
Content-Type: applicat ion/x-www-form-urlen coded
Content-Length: 9

this=that


I've tried it with "Connection: Close" at the end but it causes a bad request response (invalid verb?) and also after Content-Length which gives a valid response (Status: 200) but doesn't post any data. Without "Connection: Close" the site gives no response and my script just times out while it's waiting.

Any help would be appreciated.

Thanks
I found this comment on a board from someone who appears to of had the same problem as you - getting a 200 status but no data posted. Hope this helps. http://us3.php.net/fsockopen


"If you are composing your own HTTP POST to upload to a form or upload a file, you need to realize that when you *use* your boundary to separate the parts, you need to prepend two dashes (--) to whatever you *defined* your boundary as. For example, if you define your boundary as --1234, then you need to send ----1234 as your boundaries.

If you forget to prepend those two dashes, it is particularly frustrating because the server will return a 200 OK / accepted code, but your receiving form will not recieve any POSTed data.

I only wasted a day and a half on that one."
I found this comment on a board from someone who appears to of had the same problem as you - getting a 200 status but no data posted. Hope this helps. http://us3.php.net/fsockopen


"If you are composing your own HTTP POST to upload to a form or upload a file, you need to realize that when you *use* your boundary to separate the parts, you need to prepend two dashes (--) to whatever you *defined* your boundary as. For example, if you define your boundary as --1234, then you need to send ----1234 as your boundaries.

If you forget to prepend those two dashes, it is particularly frustrating because the server will return a 200 OK / accepted code, but your receiving form will not recieve any POSTed data.

I only wasted a day and a half on that one."
You lost me!!

Back to QA. TechInterviews.com. Powered by Yahoo! Answers and TechInterviews.com community.