带有正文表单数据的邮递员请求到 json
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49676489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Postman request with body Form data to json
提问by ValRob
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:
但是,当我尝试使用 raw(json) 中的正文发送相同的请求时,我得到了这个:
I am trying to send the data via Angular 5 to a Drupal 8 Backend.
我正在尝试通过 Angular 5 将数据发送到 Drupal 8 后端。
Thanks!
谢谢!
采纳答案by ValRob
It will depend if the backend can receive a JSON format.
这将取决于后端是否可以接收 JSON 格式。
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.
就我而言,我正在使用 Drupal 8 Module simple Oauth。OAuth 2.0 Bearer 令牌的格式实际上在单独的规范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].
实体主体遵循 HTML 4.01 [W3C.REC-html401-19991224] 定义的“application/x-www-form-urlencoded”内容类型的编码要求。
So, In my particular case, I will try to send a form-data from angular.
因此,在我的特定情况下,我将尝试从 angular 发送表单数据。
Thanks: Jean Rostan
感谢:让·罗斯坦
回答by Leandro Soriano
回答by DORRITO
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:
如上所述,如果您正在查看此问题,后端可能不接受 JSON。我遇到了完全相同的问题,但前端不同。对于一个对我有用的例子只是得到一个开始的响应,你可以使用:
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.
这是一个 async/await 格式,不包括您可能需要的几个设置步骤,包括 try/catch,但您应该能够采用上述方法并尝试将其转换为您的需要并获得所需的结果。

