Skip to content
This repository has been archived by the owner on Mar 16, 2019. It is now read-only.

Set Content-Length on POST (body as-is, iOS) #221

Closed
jbrodriguez opened this issue Dec 29, 2016 · 4 comments
Closed

Set Content-Length on POST (body as-is, iOS) #221

jbrodriguez opened this issue Dec 29, 2016 · 4 comments

Comments

@jbrodriguez
Copy link
Contributor

@wkh237 awesome work !

The library is only growing more useful every day.

I do have to say that I'm having a problem with x-www-form-urlencoded POST operations on iOS (running 0.10.1-beta.2, Android works fine), since I'm not receiving the query params on the server side.

In this line, https://github.com/wkh237/react-native-fetch-blob/blob/master/src/ios/RNFetchBlobReqBuilder.m#L145

size is unused.

As soon as I set Content-Length with size, I start getting the query params.

size = [body length];
[request setHTTPBody: [body dataUsingEncoding:NSUTF8StringEncoding]];
[request setValue:[NSString stringWithFormat:@"%u", [body length]] forHTTPHeaderField:@"Content-Length"];

This works for me.

It's a small change, but I was wondering if you deliberately weren't setting the length for some reason

@wkh237
Copy link
Owner

wkh237 commented Dec 30, 2016

@jbrodriguez , thanks for reporting this issue, from my understanding the Content-Length header will automatically added when the body is added when request:setHTTPBody (see #94), I'll do some test and report result here.

@jbrodriguez
Copy link
Contributor Author

@wkh237 great !

I'm posting some query params sent to the library as a string (not a multipart post).

I'll double check as well.

Just a note, on the Android side, you do set content-length explicitly (even if they are different libraries and all)

https://github.com/wkh237/react-native-fetch-blob/blob/master/src/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java#L75

@wkh237
Copy link
Owner

wkh237 commented Jan 4, 2017

Yeah, on Android we have to set Content-Length ourself but on IOS it's automatic. I've run some test but unable to replicate the problem you addressed. Any idea ?

@jbrodriguez
Copy link
Contributor Author

Thanks wkh237.

Not many ideas, I'll wait for the update to RN 0.40 and try again.

Closing this one for now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants