Hi everyone,
I'm building a multipart/form-data
request and have been having trouble getting it to work.
Here's what I'm sending:
POST /post.php HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-us
Connection: keep-alive
Cookie: <a cookie>
Host: myserver.com
Content-Type: multipart/form-data; boundary=1850FEA3-AEAC-46F7-A0B3-7F29DC50E873
Transfer-Encoding: Chunked
User-Agent: MyTestProgram/1 CFNetwork/454.9.7 Darwin/10.4.0 (i386) (MacBookPro5%2C3)
--1850FEA3-AEAC-46F7-A0B3-7F29DC50E873
Content-disposition: form-data; name="field2"
field2
--1850FEA3-AEAC-46F7-A0B3-7F29DC50E873
Content-disposition: form-data; name="field1"
test
--1850FEA3-AEAC-46F7-A0B3-7F29DC50E873--
(Each newline is \r\n
)
The server side (post.php
) is a simple php script to simply dump the headers and $_POST
. The $_POST
array is always empty.
I've been following this page on w3.org about how to construct a multipart/form-data request, and from what I can see, I've got it correct.
I've been staring at this for several hours and haven't made any progress on this.
Any ideas why my POST data isn't getting recognized?
edit "How are you transmitting the data to the server?"
The request body is getting generated by a custom subclass of NSInputStream, which is used by an NSURLRequest object, which is actually being transmitted by an NSURLConnection. The headers (except for Content-Type
) are all generated by these supporting classes. I generate and set the Content-Type
header myself. I didn't include this information at first because it didn't seem relevant (the transmission code is part of Mac OS X, and I really doubt it's the problem).