Problem with read_multipart when use from iPhone CFNetwork library

Hello.

iPhone use NSURLRequest, NSURLConnection to POST data to rails site. Request is the next: POST / HTTP/1.1 User-Agent: CFNetwork/330 Content-Type: multipart/form-data; boundary=------580a9a040b19fc6621c596d9c40097f7 Accept: */* Accept-Language: ru Accept-Encoding: gzip, deflate Content-Length: 295 Connection: keep-alive Host: 192.168.0.20:8888

--------580a9a040b19fc6621c596d9c40097f7 Content-Disposition: form-data; name="authenticity_token"

86a4347fae09e23cf592eed6eb324cd61f3b9e5f --------580a9a040b19fc6621c596d9c40097f7 Content-Disposition: form-data; name="picures[pic]"

111 --------580a9a040b19fc6621c596d9c40097f7--

There too mane \r\n after Host:192.168.0.20:8888, therefore rails return "Bad content body".

Could somebody fix this?

And it should. The separator of headers and body is “\r\n\r\n”. Anything else is wrong.

I understand, but it is imposible to fix Apple library.

Could you tell me, how to fix this inside the application, i do not want to 'monkey patching' rails code.

Well, you can contribute a failing test and a patch to Rails yourself. This wouldn’t be the first time Rails fixed a badly implemented HTTP spec by Apple.

Sorry, this was problem in our programmers in other department, we solve this problem.

Thanx you for help.

Can you please explain what the problem was and your solution?

I'm having the same one.

I ran into the same problem because I probably found the same example you did, which was built for use with Perl, not Rails. Perl is apparently more tolerent of simple formatting errors, which is not surprising considering Larry Wall's philosophy.The example contains a line similar to this:

[ body appendData:[[NSString stringWithFormat:@"\r\n--%@\r \n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

It turns out that is wrong. The initial \r\n should not be there, so you should have:

[ body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

Once I made that change, everything worked perfectly.

Hope that helps someone.

D