简体   繁体   English

使用静态文件时req.body为空对象,但使用邮递员时为内容

[英]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.

相关问题 使用http.post时,Express req.body为空 - Express req.body is empty when using the http.post 使用护照GoogleStrategy时Req.body为空 - Req.body empty when using passport GoogleStrategy 使用 postman 中的表单数据使 req.body 为空 - Getting req.body empty using form-data in postman Req.body 使用我自己的 fetch 为空,但适用于 postman - Req.body is empty using my own fetch, but works with postman 在nodejs express中使用表单数据过帐时,req.body返回空对象 - req.body returns empty object when posting using form data in nodejs express Nodejs:当我尝试使用 jquery - ajax 上传 img 文件时,req.body 为空 - Nodejs : req.body is empty when i try to upload a img file using jquery - ajax req.body 是 [Object: null 原型] {} 并且 req.files 在使用 multer 处理包含表单数据的 POST 请求时为空 - req.body is [Object: null prototype] {} and req.files is empty when using multer to handle POST request containing form data 即使使用bodyParser,req.body也会给出空对象{} - req.body is giving empty object {} even by using bodyParser 当我提交 PUT 请求时,我的 req.body object 显示为空。 我正在使用方法覆盖中间件 - My req.body object is showing as empty when I submit a PUT request. I am using the method override middlware 当我使用正文解析器时,为什么 req.body 未定义? - Why is req.body undefined when im using a body parser?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM