[英]req.body an empty object when using a static file but has content when using postman
I have an express API that sends a static html file that it self has a script tag with a fetch request. 我有一个表达API,它会发送一个静态html文件,该文件本身具有一个带有提取请求的脚本标签。 That request goes to the same API but a different route.
该请求转到相同的API,但路由不同。 When I do the request with postman the body has content but not when I do it through chrome.
当我向邮递员提出请求时,身体有满足感,但当我通过chrome处理时没有。 So I'm curious what postman is doing differently?
所以我很好奇邮递员在做什么?
Ive changed the content-type headers as well as having messed around with the form's enctype and a bunch of additional things. Ive更改了内容类型标题,并弄乱了表单的enctype和许多其他内容。
It's easier to just link the github project : https://github.com/dshrops1/helio-teams 链接github项目更容易: https : //github.com/dshrops1/helio-teams
the static file I serve is under servers/authen/expressfiles 我提供的静态文件位于server / authen / expressfiles下
Any help or resources would be appreicated. 任何帮助或资源将不胜感激。
edit: { 'object Object': '' }
is what is in the body when done from the browser , when done from postman I get the actual body { user: "blalba" , pass: "blala"}
or something along those lines 编辑:
{ 'object Object': '' }
是浏览器中的内容,邮递员中的内容是实际的内容{ user: "blalba" , pass: "blala"}
或类似内容
Okay so Im not sure why I could not send json like I have done with my other forms using the right Content-type and JSON.Stringify(), but for some reason on my express server it would give me an empty object. 好的,我不确定我为什么不能像使用正确的Content-type和JSON.Stringify()处理其他表单一样发送json,但是由于某些原因,在我的快速服务器上,它会给我一个空对象。
So the solution was making sure my form was using x-www-form-urlencoded and then figuring out how to send data in the body with that type of form data and it required me to send a template string such as: 因此,解决方案是确保我的表单使用x-www-form-urlencoded,然后弄清楚如何使用该类型的表单数据在正文中发送数据,并且它要求我发送模板字符串,例如:
fetch("/urlfetchingfrom", {
method: "POST",
....
body: `id1=${value}&id2=${value2}`
})
doing this allowed me to gain access to the data on my server. 这样做使我能够访问服务器上的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.