Open Chandragandla opened 7 years ago
I need to be able to download documents from a "logged in" session on a web server. All is working well on iOS where the Cookies are sent, but it fails on Android. A fix would be much welcome.
Cookie support is still work in progress, and I think there is still a lot of problems need to be solved.
Besides, you can have a look at RNFetchBlob.net, and add cookies manually into headers.
@wkh237 Cool, thanks. Can't quite get it to work with a specific host, but for now I'll just grab all hosts.
@wkh237 ,@Jacse,could you please tell me how to add cookies manually into headers.I add 'Cookie',but it didn't work
@zuzuviewer , it's not supported ATM, I'll add this one when I have time. Please have a look #157
@zuzuviewer unfortunately I was only able to retrieve the cookies, not send them again. As you say, they are not sent in the request even when added as a header. @wkh237 let me know if I can do anything to speed things up, not very strong i Java though.
I've done some testing and it seems that RNFetchBlob
completely ignores the specified Cookie
-header. It does send cookies, but only cookies that are set through RNFetchBlob
-fetches, not regular fetches. This leads to having two different sets of cookies for RNFetchBlob
and regular fetch
.
What I described in my previous post happens due to line #303
in RNFetchBlobReq.java
: clientBuilder.cookieJar(new RNFBCookieJar());
As this sets a new custom cookie jar.
I got it all working by deleting said line and using facebooks OkHttpClientProvider.getOkHttpClient();
instead of initializing a new OkHttpClient
. In this way, cookies set in a regular fetch persist across fetches in RNFetchBlob
as well.
@Jacse Do you have a branch going with that fix?
@nikolaiwarner I do now: #388 👍
@Jacse I am having the same problem as the original person. I need to use credentials: 'include' to pass cookies to the API. Can you provide an example of how to do this with your merged code?
@MEDLJosh it should work straight out of the box. If you use the regular fetch to get cookies, these cookies should be sent along with your react-native-fetch-blob
request as well.
@Jacse is there a way to confirm this is happening clientside? cookie received with fetch is attaching fine to my fetch GET requests but not in react-native-fetch-blob it seems...
From looking at the code, I don't think that cookies are being sent if you use the Download Manager. The download manager sets up it's own request and doesn't make use of the okhttp3 client so that doesn't share the cookie jar. Would it be possible to grab the same-origin cookies from the cookie jar and inject them into the download request with it's addRequestHeader() method?
any progress?
@danna88 on what specifically?
@Jacse Is download with credentials: 'include' working ? do you have work around for this?
Hi, I am using RN@0.34, RNFB@0.10.1-beta.3 and node/express.
Below is the code I use to send the uploaded document.
return RNFetchBlob.fetch('POST', nodeUrl, { 'Content-Type' : 'multipart/form-data', }, [{ name : 'file', filename : 'sample.png', data : wrappedURI }])
Session cookies are sent correctly for iOS , but for android, cookies are not being sent and user is getting logged out.How can I inlcude
credentials: 'include',
with the request ?Any help is greatly appreciated.
Thanks