tags:

views:

30

answers:

1

In C#, I am working on a project to automatically update a separate server with an image and other form data and such... However, the PHP server isn't getting any of the POST data, it's only getting the headers and I can't figure out why.

Here is what I am sending to the server (all new lines have CRLF):

POST /new_reply/1 HTTP/1.1
Host: 192.168.1.104
User-Agent: Update Bot
Cookie: SID=sib5m5lgaq66vfp2nfhpab6ug0;UID=bot
Content-Type: multipart/form-data; boundary=-----xxx
Content-Length: 1903

-----xxx
Content-Disposition: form-data; name="form_sent"

1
-----xxx
Content-Disposition: form-data; name="name"


-----xxx
Content-Disposition: form-data; name="body"

hej fra mig
-----xxx
Content-Disposition: form-data; name="image"; filename="test.jpg"
Content-Type: image/jpeg

(image data)
-----xxx
Content-Disposition: form-data; name="post"

Post
-----xxx--

Here is the image with the hidden characters show of the request: http://img823.imageshack.us/img823/9352/requestv.png

Here is the PHP print_r of $_REQUEST on the page /new_reply/1:

Array
(
    [reply] => 1
    [SID] => sib5m5lgaq66vfp2nfhpab6ug0
    [UID] => bot
)

As you can see, none of the post is coming through...

+1  A: 

I'm pretty sure that the boundary specified in the Content-Type header is wrong. It should be something like this:

Content-Type: multipart/form-data; boundary=RANDOM_STRING_BOUNDARY
--RANDOM_STRING_BOUNDARY
Content-Disposition: form-data; name="image_name"

Monkey
--RANDOM_STRING_BOUNDARY
Content-Disposition: form-data; name="photo"; filename="monkey.png"
Content-Type: image/png

[ here would be the png file in binary form ]
--RANDOM_STRING_BOUNDARY--

As you can see, RANDOM_STRING_BOUNDARY has no hyphens prepended when specified in the Content-Type header, only in the subsequent headers where it is actually used. Also, the last usage appends two new hyphens (but you already knew that).

Ionuț G. Stan
You are a god. Thank you so much!
kevin
He, I've been bitten by something similar. For me, it was the trailing hyphens that were missing :)
Ionuț G. Stan