简体   繁体   中英

I receive a 401 error from the server when trying to authenticate a user in my React Native app on Android

I described my problem in the title.

Some additional info:

0) When I enable the Network Inspect in the React Native Debugger, everything works fine, and I don't have such a problem.

1) I use expo for my App.

2) I checked the problem on Android emulator (android v. 10) and on real android device (android v. 7) - the result is the same.

3) The problem is not repeated for iOS simulator.

4) I'm trying to make a GET request to remote server https://.../client/authorize and pass a JWT with user's email address in the Authorization: Bearer header.

5) I use the axios library for requests, but I have the same problem when I use native fetch .

6) Expo version is 35.0.0

7) When I disable Network Inspect in the React Native Debugger the problem with authorization on Android devices is back.

Thanks in advance for your answers.

You're probably going to have to sit down with the owner of the back end to get this figured out. And it gets more complicated if the server is being hosted by another service.

I had a similar issue not long ago: CloudFlare (Memberful) post requests from Java produce a 403 error

Figuring out that, in my case, the agent value was causing the issue was very tricky since I couldn't sit down with the server owner. What I had to do was use Fiddler and Wireshark to compare the requests that were being sent, identify the differences, and then try them out one-by-one using Advanced REST Client (ARC).

It's tedious, but that's how I had to do it. If you can sit with the server owner though, they should be able to tell you what they're receiving and what elements of those requests are causing the issue. They might need to change some configuration on their end.

Hope this helps, and best of luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM