Ola
I'm trying to access a REST API and the only way that it works for now is if I have a plugin on the google browser to bypass the CORS error and return my data.
From the understanding of how CORS works, this is implemented at the browser level to validate and beef up security.
The error I am getting is.
For the header, I only need to pass basic authorization.
This is my code
So I pass my username and password here. I understand this is due to a missing, "Access-Control-Allow-Origin: *"
How can I fix this so that I dont have to use a browser plugin?
Thanks
PS: I am able to get the data from the REST API when this browser plugin is installed and activated.
mybrowseraddon.com
I'm trying to access a REST API and the only way that it works for now is if I have a plugin on the google browser to bypass the CORS error and return my data.
From the understanding of how CORS works, this is implemented at the browser level to validate and beef up security.
The error I am getting is.
B4X:
Access to XMLHttpRequest at 'https://api.sigfox.com/v2/devices/' from origin 'https://localhost' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
For the header, I only need to pass basic authorization.
B4X:
'set authorization for this connection
Sub BasicAuthorization(username As String, password As String) As Map
Dim usernamepassword As Object = BANano.ToBase64($"${username}:${password}"$)
Dim basic As String = $"Basic ${usernamepassword}"$
Dim m As Map = CreateMap()
m.Put("Authorization", basic)
Return m
End Sub
This is my code
B4X:
Dim hdr As Map = BasicAuthorization(una, pwd)
'
options.Initialize
options.Method = "GET"
options.Headers = hdr
'
fetch.Initialize("https://api.sigfox.com/v2/devices/", options)
BANano.Await(fetch)
fetch.Then(response)
fetch.Return(response.json)
fetch.Then(data)
Log(data)
fetch.Else(error)
Log(error)
fetch.End
So I pass my username and password here. I understand this is due to a missing, "Access-Control-Allow-Origin: *"
How can I fix this so that I dont have to use a browser plugin?
Thanks
PS: I am able to get the data from the REST API when this browser plugin is installed and activated.

Allow CORS: Access-Control-Allow-origin
Easily add (Access-Control-Allow-Origin: *) rule to the response header.

Last edited: