![](/img/trans.png)
[英]Postman returns 415 when trying to do a POST using form-data, but the same request with JSON works fine
[英]Using postman to test POST request, how do I access the form-data inside the request?
我已经搜索了几个小时,我需要帮助。 我不认为我使用的是正确的单词。 无论如何,我正在使用Claudia.JS为我的AWS Lambda函数设置POST请求。 这是该函数的基础:
api.post('/leads', function (request) {
console.log(request);
return request;
});
当我使用邮差测试发布请求时,我返回了请求对象。 真棒。 然后,我尝试通过表单数据。 我将密钥设置为“用户名”,并将值设置为“这是用户名”。 这是request.body是:
"body": "---------------------------
-019178618034620042564575\r\nContent-Disposition: form-data;
name=\"username\"\r\n\r\nthis is the username\r\n----------------------
------019178618034620042564575--\r\n",`
我以为我可以返回request.body.username ...来键入username的值...但是我丢失了一些东西。
如何访问请求中的表单数据?
更新:好的。 网站正在接收表单数据,发出过帐请求...此功能正在接收过帐请求吗? 仍然-在邮递员中...如果我要在其中放入自己的JSON ...为什么我不能像... request.body.username那样访问request.body?
您应该尝试console.log(request.data)
来查看您的请求对象,即。 就我自己而言,我可以看到请求正文的内容。
请访问https://www.getpostman.com/docs/postman/scripts/postman_sandbox以查看有关您请求的所有相关信息。
我通过查看邮递员中设置的标题解决了这个问题。 它被设置为表单数据,而不是应用程序/ JSON。 现在所有肉汁。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.