问题
I have a problem with postman...
For one side, I can make this request with the body in form data.
But, when I try to send the same request with the body in raw(json) I got this:
I am trying to send the data via Angular 5 to a Drupal 8 Backend.
Thanks!
回答1:
Try adding to the Headers the Content-Type: application/json
回答2:
It will depend if the backend can receive a JSON format.
In my case, I am working with the Drupal 8 Module simple Oauth. and the The format for OAuth 2.0 Bearer tokens is actually described in a separate spec, RFC 6750.
More concrete here
The entity-body follows the encoding requirements of the "application/x-www-form-urlencoded" content-type as defined by HTML 4.01 [W3C.REC-html401-19991224].
So, In my particular case, I will try to send a form-data from angular.
Thanks: Jean Rostan
回答3:
As stated above, the backend may not accept JSON if you are viewing this question. I was having the exact same issue but with a different front end. For an example that worked for me to just get a starting response, you might use:
const axios = require("axios");
const querystring = require("querystring");
const authenticate = async () => {
.post((req, res) => {
let authData = {
grant_type: "password",
client_id: "id",
client_secret: "secret",
username: "name",
password: "password"
};
const authResponse = await axios.post(
"http://blah.com/endpoint",
querystring.stringify(authData)
);
return res.send(authResponse.data);
}
authenticate()
This is in a async/await format that excludes a couple setup steps that you may need including try/catch, but you should be able to take the above and attempt to convert it to your needs and get the needed result.
来源:https://stackoverflow.com/questions/49676489/postman-request-with-body-form-data-to-json