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. That request goes to the same API but a different route. When I do the request with postman the body has content but not when I do it through 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.
It's easier to just link the github project : https://github.com/dshrops1/helio-teams
the static file I serve is under servers/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
node.js forms google-chrome express
add a comment |
I have an express API that sends a static html file that it self has a script tag with a fetch request. That request goes to the same API but a different route. When I do the request with postman the body has content but not when I do it through 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.
It's easier to just link the github project : https://github.com/dshrops1/helio-teams
the static file I serve is under servers/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
node.js forms google-chrome express
add a comment |
I have an express API that sends a static html file that it self has a script tag with a fetch request. That request goes to the same API but a different route. When I do the request with postman the body has content but not when I do it through 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.
It's easier to just link the github project : https://github.com/dshrops1/helio-teams
the static file I serve is under servers/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
node.js forms google-chrome express
I have an express API that sends a static html file that it self has a script tag with a fetch request. That request goes to the same API but a different route. When I do the request with postman the body has content but not when I do it through 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.
It's easier to just link the github project : https://github.com/dshrops1/helio-teams
the static file I serve is under servers/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
node.js forms google-chrome express
node.js forms google-chrome express
edited Nov 15 '18 at 3:25
Daredevil
39511
39511
asked Nov 15 '18 at 1:28
Dustin.ShropshireDustin.Shropshire
187
187
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
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:
fetch("/urlfetchingfrom",
method: "POST",
....
body: `id1=$value&id2=$value2`
)
doing this allowed me to gain access to the data on my server.
So it actually came down to being a CORS issue that I just did not understand well enough and I'm back to using application/json but there server is using CORS
– Dustin.Shropshire
Nov 15 '18 at 6:15
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53311176%2freq-body-an-empty-object-when-using-a-static-file-but-has-content-when-using-pos%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
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:
fetch("/urlfetchingfrom",
method: "POST",
....
body: `id1=$value&id2=$value2`
)
doing this allowed me to gain access to the data on my server.
So it actually came down to being a CORS issue that I just did not understand well enough and I'm back to using application/json but there server is using CORS
– Dustin.Shropshire
Nov 15 '18 at 6:15
add a comment |
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.
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:
fetch("/urlfetchingfrom",
method: "POST",
....
body: `id1=$value&id2=$value2`
)
doing this allowed me to gain access to the data on my server.
So it actually came down to being a CORS issue that I just did not understand well enough and I'm back to using application/json but there server is using CORS
– Dustin.Shropshire
Nov 15 '18 at 6:15
add a comment |
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.
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:
fetch("/urlfetchingfrom",
method: "POST",
....
body: `id1=$value&id2=$value2`
)
doing this allowed me to gain access to the data on my server.
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.
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:
fetch("/urlfetchingfrom",
method: "POST",
....
body: `id1=$value&id2=$value2`
)
doing this allowed me to gain access to the data on my server.
answered Nov 15 '18 at 5:08
Dustin.ShropshireDustin.Shropshire
187
187
So it actually came down to being a CORS issue that I just did not understand well enough and I'm back to using application/json but there server is using CORS
– Dustin.Shropshire
Nov 15 '18 at 6:15
add a comment |
So it actually came down to being a CORS issue that I just did not understand well enough and I'm back to using application/json but there server is using CORS
– Dustin.Shropshire
Nov 15 '18 at 6:15
So it actually came down to being a CORS issue that I just did not understand well enough and I'm back to using application/json but there server is using CORS
– Dustin.Shropshire
Nov 15 '18 at 6:15
So it actually came down to being a CORS issue that I just did not understand well enough and I'm back to using application/json but there server is using CORS
– Dustin.Shropshire
Nov 15 '18 at 6:15
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53311176%2freq-body-an-empty-object-when-using-a-static-file-but-has-content-when-using-pos%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown