use-http
use-http copied to clipboard
useFetch `post` call inserts quotes when passed a string
Describe the bug
useFetch post call inserts quotes when passed a string.
⚠️ Make a Codesandbox ⚠️ Please click this to easily reproduce the bug.
To Reproduce Steps to reproduce the behavior:
- Go to https://codesandbox.io/s/strange-wave-onbnw?file=/src/App.js
- Open devtools and observe network call to `/test'
- View request payload
- See that "test" is exctly that. The word "test" wrapped in quotes.
Expected behavior I expect a string to be passed into the body of the request as a string, not wrapped in quotes.
You need something like this?
await post("/test", {test: "test"});
No I need specifically to be able to pass any string value at all. I'll update the sandbox shortly to reflect when I'm actually doing in my app, but the short version is that in order to do a URL encoded form post like a normal HTML form, a typical fetch call would be passing plane string not an object
From: João Arieira @.>
Sent: Friday, January 21, 2022 11:47:41 AM
To: ava/use-http @.>
Cc: Stephen Collins @.>; Author @.>
Subject: Re: [ava/use-http] useFetch post call inserts quotes when passed a string (Issue #360)
You need something like this? await post("/test", {test: "test"});
— Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fava%2Fuse-http%2Fissues%2F360%23issuecomment-1018680215&data=04%7C01%7C%7Ca4122eac8a4a49155a4608d9dcfdbe09%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637783804638167201%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=Hjh7MHwwoDSmMVzDm5522Uu6sozSy17C%2B5oJT%2FHEWw4%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FABODKJIW53556AYQ2FNVPTTUXGE23ANCNFSM5MN2B4YQ&data=04%7C01%7C%7Ca4122eac8a4a49155a4608d9dcfdbe09%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637783804638167201%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=NAD%2BTumtCqV4KIamkSSl5Zrj79kSi%2B4Whs6OfKb4c4Q%3D&reserved=0. Triage notifications on the go with GitHub Mobile for iOShttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fapps.apple.com%2Fapp%2Fapple-store%2Fid1477376905%3Fct%3Dnotification-email%26mt%3D8%26pt%3D524675&data=04%7C01%7C%7Ca4122eac8a4a49155a4608d9dcfdbe09%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637783804638177193%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=OBB2%2Fo0%2F4jJ2hn9Sg%2B7MmpzrJNuMlorkPN8CNSIr7tE%3D&reserved=0 or Androidhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dcom.github.android%26referrer%3Dutm_campaign%253Dnotification-email%2526utm_medium%253Demail%2526utm_source%253Dgithub&data=04%7C01%7C%7Ca4122eac8a4a49155a4608d9dcfdbe09%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637783804638187190%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=n5FGW0n7HdHMeMXp7V%2F41ytXJ8zWKwm4q7aNVIIXngI%3D&reserved=0. You are receiving this because you authored the thread.Message ID: @.***>
I'm afraid I can't help you. This should help: https://use-http.com/#/?id=file-upload-formdata
I've updated the sandbox. No, that link doesn't help, unfortunately because I'm not using FormData, I need to just pass a string. https://codesandbox.io/s/bold-stallman-xf6ko?file=/src/App.js
This also breaks XML bodies, which are incorrectly formatted as strings rather than plain XML values. Sending the exact same body using native fetch works, but breaks when using the hook.
I'm afraid I can't help you.
Doesn't this hook use the native fetch under the hood? If so, why is the default behaviour modified?