Android Question Setting cookies for an HttpJob doesn't work for seemingly no reason.

Yuri Cinesi

Active Member
Licensed User
Here is what I'm basically doing: I check if a text file containing the stored cookies exists, if it doesn't then I use webviewextra to run some javascript on the login page and log in. Following that I use cookiemanager to extract the cookies and save them to the aforementioned file.
If the file does exist then an HttpJob is defined and I use Job.GetRequest.SetHeader("Cookie",File.Readstring(File.DirInternal,"LoginCookies") to read the file and add the cookies to the httpjob. Of course that line is after the download.

Now here's the tricky part. The code that handles getting the cookies works perfectly fine. However in my main project the cookies don't work. When I tried creating a smaller project to reproduce the bug I was unable to, despite the code handling the cookies being identical.

I have no clue why this happens. I've tried clearing the header - it did nothing. I have also tried clearing the project.

I'm honestly at a loss on this issue. Every variable is, as far as I can tell, the same between the actual project and the test case. Same page, same login, same download method. Any help would be GREATLY appreciated.
 

Yuri Cinesi

Active Member
Licensed User
I can indeed find it. It seems to be correctly updated and everything. It still doesn't work.

The exact same cookie header however, when used in the other application, works just fine. I'm at a loss.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
For my clarification, what does not work in the larger application? Getting the cookies and storing them in a file or reading the cookies from a file and using them to create another GET request (via download() method)?
 
Upvote 0

Yuri Cinesi

Active Member
Licensed User
Getting cookies works perfectly fine. The issue is that despite me applying them to the httpjob and them showing up in the debugger the job doesn't authenticate correctly. I'm checking for a specific string that only shows up if the user is logged in which is how I know.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Are you in control of the receiving application? What does it get? Any cookies at all?
 
Upvote 0

Yuri Cinesi

Active Member
Licensed User
I am sadly not in control of the receiving application. It's a website I don't control.
As far as B4A is concerned though the cookies are there.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
You need something to capture the outgoing traffic to the website. Something like https://www.wireshark.org/. Then you can see if the cookies are sent out to the website.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Try this url in your code. Just make sure you're not using a cookie file that has valid login information. See if the cookies go out. Please, only change the URL and scramble the cookies in the file (don't add or delete). See if it sees the cookie header. Note: I have never used this site, I just googled for something easier than WireShark.

URL: https://request.urih.com/
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
What version of B4A? Are you using the standard libraries for HTTP access? Which ones? Are you using a modified version of the libraries (by including the class libraries)?
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Copy the cookies from the site to notepad. Repeat the experiment with your working test version with that url and see if you see any anomalies/differences in the cookies.
 
Upvote 0

Yuri Cinesi

Active Member
Licensed User
I honestly can't find anything. In the main app the cookies seem correct as far as I can tell, yet it doesn't work with the actual website.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
The same cookies, the exact same cookies work with the test application and the real website but not with the big application and the real website? URLs are the same, cookies are the same, etc site from which cookies come is the same...
 
Upvote 0

Yuri Cinesi

Active Member
Licensed User
Everything is identical. I copy the exact same cookies and use them in the test application and they work. The URL is the same and all that jazz.
If you'd like I can change share the application via PMs. I'll change the login details so that I don't give you the password I usually use but it's not like you can actually do anything with that account. It's just a testing one so it has no permissions.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
What is the response from the server?
 
Upvote 0
Top