-
-
Notifications
You must be signed in to change notification settings - Fork 11k
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
axios.post() requests do not send headers and payload as expected #827
Comments
You aren't configuring the request correctly. The You can see an example request with content type |
|
Hi guys, I opened a ticket that I believe that it might be related to this issue. #1149 |
I discovered that for this particular scenario (calling oauth/token endpoint) axios seems to be case sensitive for the content-type header key. 'Content-Type' works fine but 'content-type' results in a missing grant-type. I am running 0.18.0. Right now I am slammed with work - otherwise I would step into the debugger to see what is going on. Maybe the folks who are very knowledgeable with the internals of axios can either confirm or reject my statement. I do want to state that I use axios extensively in my work - kudos the the author. |
It looks like you only have two points left to make it work : one : the http method should be set to POST instead of GET since you want to send something. two : you can then add the http header (like what you did with the authorization header) Content-Type: 'application/json` On the back-end don't forget to use some kind of body parser utility package like this one : body-parser and set it up with your app. I suppose your server is using express, here is how you will do it with express : const express = require('express');
const app = express();
const bodyParser = require('body-parser')
const jsonParser = bodyParser.json();
app.use(jsonParser); // use it globally
app.get('your_route', jsonParser, otherMiddleware, (req, res) => ...); // use it for specific routes
/* ... rest of your code */ |
The Axios .post() function is not working as I expected it to.
Sitting on the serverside Java debugger I have grabbed the MimeHeader's sent to the server by Axios and also by (ubuntu) cURL.
The java server-side class is org.apache.catalina.connector.CoyoteAdapter.
The debugger is in the service(Request, Response) method (version tomcat-embed-core-8.5.6.jar, line: 308).
I issued 3 'login' requests and compared the results.
Neither of the 2 Axios calls sends the request as I expect it should do.
Here is the CURL:
curl -X POST -vu webui:webuisecret http://localhost:8081/merchant/oauth/token -k -H "Accept: application/json" -d "password=merchant1&username=merchant1&grant_type=password&scope=read%20write&client_secret=webuisecret&client_id=webui"
and here are captured the
All good so far.
[AXIOS - TEXT NAMES]
Then I sent the request with this Axios JS code:
The server responds with an error : "provider.endpoint.TokenEndpoint : Handling error: InvalidRequestException, Missing grant type".
From this, it sounds like the body is not being properly submitted (hence deciding to look at the headers and payload on the server).
Here is what we see on the server:
The requested Basic Auth does seem to be successfully applied with Axios.
However:
[AXIOS - FIELD NAMES]
And, I get the same result if I use the field name equivalents for the headers{accept} and body {*} segments:
Results in:
Here is my package.json content:
Can somebody please help me to identify what is wrong with my .post() request ?
The text was updated successfully, but these errors were encountered: