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

Android - send session cookies #220

Open
Chandragandla opened this issue Dec 28, 2016 · 17 comments
Open

Android - send session cookies #220

Chandragandla opened this issue Dec 28, 2016 · 17 comments

Comments

@Chandragandla
Copy link

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

@Jacse
Copy link
Contributor

Jacse commented Mar 31, 2017

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.

@wkh237 wkh237 mentioned this issue Mar 31, 2017
4 tasks
@wkh237
Copy link
Owner

wkh237 commented Mar 31, 2017

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.

@Jacse
Copy link
Contributor

Jacse commented Mar 31, 2017

@wkh237 Cool, thanks. Can't quite get it to work with a specific host, but for now I'll just grab all hosts.

@zuzuviewer
Copy link

zuzuviewer commented Apr 24, 2017

@wkh237 ,@Jacse,could you please tell me how to add cookies manually into headers.I add 'Cookie',but it didn't work

@wkh237
Copy link
Owner

wkh237 commented Apr 25, 2017

@zuzuviewer , it's not supported ATM, I'll add this one when I have time. Please have a look #157

@Jacse
Copy link
Contributor

Jacse commented May 9, 2017

@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.

@Jacse
Copy link
Contributor

Jacse commented May 21, 2017

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.

@Jacse
Copy link
Contributor

Jacse commented Jun 3, 2017

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.

@nikolaiwarner
Copy link

@Jacse Do you have a branch going with that fix?

@Jacse
Copy link
Contributor

Jacse commented Jun 5, 2017

@nikolaiwarner I do now: #388 👍

@MEDLJosh
Copy link

@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?

@Jacse
Copy link
Contributor

Jacse commented Jul 1, 2017

@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.

@f6m6
Copy link

f6m6 commented Jul 27, 2017

@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...

@dominic3
Copy link

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?

@Ariel08081214
Copy link

any progress?

@Jacse
Copy link
Contributor

Jacse commented Feb 7, 2018

@danna88 on what specifically?

@yoginair
Copy link

@Jacse Is download with credentials: 'include' working ? do you have work around for this?

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