Problem with read_multipart when use from iPhone CFNetwork library


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

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

Content-Disposition: form-data; name="picures[pic]"


There too mane \r\n after Host:, 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]

Once I made that change, everything worked perfectly.

Hope that helps someone.