Michael Filippo
Michael Filippo

Reputation: 41

React Native - Request with URL that includes credentials

So I have to make requests to various urls with different domains which contains credentials

I've successfully managed to send one like this:

const resp = await fetch(`my-url-here`, {
            method: 'POST',
            headers: {
                'Access-Control-Allow-Origin': '*',
                'Content-Type': 'application/json',
                'Authorization': `Basic ${base64.encode(my-key-here)}`
            },
            body: JSON.stringify(data)
        })

However this works only for one domain while on the other I keep getting

[TypeError: Network request failed] on Android

[SyntaxError: JSON Parse error: Unexpected identifier "undefined"] on iOS (while executing the .json() method; I think the request is successful but with an empty response)

Every call on these domains work correctly using PostMan/ThunderClient

Any idea how to solve this?

Upvotes: 0

Views: 423

Answers (1)

Geeks Era
Geeks Era

Reputation: 31

Please share how you are processing response seems like request works fine but somehow there is an error while parsing the data into JSON.

invalid data contains in response which is not able to parse into JSON.

Upvotes: 1

Related Questions