-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
POST requests that work with Axios throw CORS error with Redaxios #84
Comments
@developit any thoughts on this? Is Redaxios supposed to support |
Are you able to show the CORS preflight request and response? It seems like the cors error is masking a failure here relating to the request body encoding. In your example code, what is the My guess right now is that Axios automatically switches to form-encoding object body values if an x-www-form-encoded content-type is set. One way to check this would be to see if the following works: const response = await axios({
method: 'POST',
url: getApiUrl(),
data: new URLSearchParams(formData),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
}); |
Thanks very much for your reply @developit!
It is. I tried now with your suggestion but unfortunately it fails in a different way. I no longer see a CORS error, but instead the API endpoint doesn't respond as expected - it returns an HTTP 200 OK status code, but the actual API code fails to process the passed data properly, and returns a failure message. The Axios payload looks like below - and the failing Redaxios payload (without {"endpoint":"ourEndpoint","name":"test","email":"[email protected]","applicationVersion":"x.x.x","issue":"test only"} The Redaxios payload (with
The request headers (minus the User-Agent) for Axios look like this:
For Redaxios (without
and with
Any clues there? I see differences in the |
Ah I think I've found a fix, and it's quite simple! It looks like Axios maybe applies Indeed, wrapping our code to look like this works: data: JSON.stringify({
...formData,
}), Is this logic something you'd be open to integrating into I suspect the |
Friendly bump. @developit what do you think? Could this be integrated directly into redaxios? |
Friendly bump @developit, whenever you have a chance. I think this would be a valuable addition to Redaxios. |
Friendly bump. |
Hey, sorry for the inactivity on this. I haven't had time to make the change because it requires a fair amount of byte-shaving to offset (the string "application/x-www-form-encoded" is very long). I'm hoping I can come up with a clever solution (eg: browser sending the header by using FormData to encode?), but haven't found one yet. The affected lines are these ones: Lines 174 to 175 in ad40de9
|
Thanks for the update @developit! |
First, thank you for this awesome project! What a huge transfer size savings Redaxios is over Axios.
We have some code like below that works fine with Axios but fails with Redaxios:
We get:
It seems possibly related to this question/answer
The text was updated successfully, but these errors were encountered: