JS translate XMLHttpRequest to Fetch-function (GET): Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have bodyCORS with XMLHttpRequest not workingService Workers: Retrieve xhr body when fetching the requestXHR POST Cannot send credentials and headerAngular2 CORS error when being redirected from API to Identityserverhow to get headers from xhr?React Native - Can't get token from asp.net web apiFile upload to pre-signed url of S3 in React Native - Header is getting appendedBody not sent in “fetch” POST request and (my) solutionCross-Origin Read Blocking on React app but not LaravelTabulator ajax request and CORS
Can I use a Cat5e cable with an RJ45 and Cat6 port?
How can I get people to remember my character's gender?
Is there precedent or are there procedures for a US president refusing to concede to an electoral defeat?
What to use instead of cling film to wrap pastry
To kill a cuckoo
Where are the "shires" in the UK?
Start job from another SQL server instance
Out of scope work duties and resignation
How should I tell my manager I'm not paying for an optional after work event I'm not going to?
Is the book wrong about the Nyquist Sampling Criterion?
Has the Hulk always been able to talk?
Why does sound not move through a wall?
Which US defense organization would respond to an invasion like this?
Are there terms in German for different skull shapes?
What do "Sech" and "Vich" mean in this sentence?
Why symmetry transformations have to commute with Hamiltonian?
Any examples of liquids volatile at room temp but non-flammable?
Are the Night's Watch still required?
Should homeowners insurance cover the cost of the home?
Hostile Divisor Numbers
Why didn't this character get a funeral at the end of Avengers: Endgame?
When an imagined world resembles or has similarities with a famous world
Indentation Tex
Why did WWI include Japan?
JS translate XMLHttpRequest to Fetch-function (GET): Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body
CORS with XMLHttpRequest not workingService Workers: Retrieve xhr body when fetching the requestXHR POST Cannot send credentials and headerAngular2 CORS error when being redirected from API to Identityserverhow to get headers from xhr?React Native - Can't get token from asp.net web apiFile upload to pre-signed url of S3 in React Native - Header is getting appendedBody not sent in “fetch” POST request and (my) solutionCross-Origin Read Blocking on React app but not LaravelTabulator ajax request and CORS
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
How to convert old XMLHttpRequest based code to FETCH function?
An old code:
var data = JSON.stringify(
"username": "user",
"token": "12345"
);
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.open("GET", "http://localhost:5000/v1/data/users/");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
I can't send data-fields thro GET request
I have tryed:
fetch (url, method: 'GET',
mode:"cors",
body: JSON.stringify(
username,
token
),
headers:
'Content-Type': 'application/json'
)
but i have caught Fetch Error: TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.
get xmlhttprequest fetch
add a comment |
How to convert old XMLHttpRequest based code to FETCH function?
An old code:
var data = JSON.stringify(
"username": "user",
"token": "12345"
);
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.open("GET", "http://localhost:5000/v1/data/users/");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
I can't send data-fields thro GET request
I have tryed:
fetch (url, method: 'GET',
mode:"cors",
body: JSON.stringify(
username,
token
),
headers:
'Content-Type': 'application/json'
)
but i have caught Fetch Error: TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.
get xmlhttprequest fetch
It seems like the error message is pretty clear: GET requests can’t have a request body, but your code is trying to send a GET request with anapplication/json
request body. Why are you trying do that? Why aren’t you just using a POST request instead?
– sideshowbarker
Mar 23 at 0:51
Using the POST-request have to lead change back-end legacy code, it is not in my competence. If i will have not solved at next week with FETCH-function, i will code a Promise-wrapper around XMLHttpRequest
– Gerasim Gerasimov
Mar 23 at 4:35
Have you got an idea, how the POSTMAN doing that? get-header. get-body.
– Gerasim Gerasimov
Mar 24 at 6:58
Postman is able to send GET requests that have a request body because like other general HTTP clients there are no restrictions on the characteristics of HTTP requests it can make. But the the case of the Fetch API, the Fetch spec places an explicit restriction on what kind of GET requests you can make with the API. See fetch.spec.whatwg.org/#ref-for-dom-requestinit-body%E2%91%A0: “If either init["body"] exists and is non-null or inputBody is non-null, and request’s method isGET
orHEAD
, then throw a TypeError.”
– sideshowbarker
Mar 24 at 9:45
add a comment |
How to convert old XMLHttpRequest based code to FETCH function?
An old code:
var data = JSON.stringify(
"username": "user",
"token": "12345"
);
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.open("GET", "http://localhost:5000/v1/data/users/");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
I can't send data-fields thro GET request
I have tryed:
fetch (url, method: 'GET',
mode:"cors",
body: JSON.stringify(
username,
token
),
headers:
'Content-Type': 'application/json'
)
but i have caught Fetch Error: TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.
get xmlhttprequest fetch
How to convert old XMLHttpRequest based code to FETCH function?
An old code:
var data = JSON.stringify(
"username": "user",
"token": "12345"
);
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.open("GET", "http://localhost:5000/v1/data/users/");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
I can't send data-fields thro GET request
I have tryed:
fetch (url, method: 'GET',
mode:"cors",
body: JSON.stringify(
username,
token
),
headers:
'Content-Type': 'application/json'
)
but i have caught Fetch Error: TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.
get xmlhttprequest fetch
get xmlhttprequest fetch
edited Mar 23 at 0:50
sideshowbarker
34.6k1684100
34.6k1684100
asked Mar 22 at 16:47
Gerasim GerasimovGerasim Gerasimov
13
13
It seems like the error message is pretty clear: GET requests can’t have a request body, but your code is trying to send a GET request with anapplication/json
request body. Why are you trying do that? Why aren’t you just using a POST request instead?
– sideshowbarker
Mar 23 at 0:51
Using the POST-request have to lead change back-end legacy code, it is not in my competence. If i will have not solved at next week with FETCH-function, i will code a Promise-wrapper around XMLHttpRequest
– Gerasim Gerasimov
Mar 23 at 4:35
Have you got an idea, how the POSTMAN doing that? get-header. get-body.
– Gerasim Gerasimov
Mar 24 at 6:58
Postman is able to send GET requests that have a request body because like other general HTTP clients there are no restrictions on the characteristics of HTTP requests it can make. But the the case of the Fetch API, the Fetch spec places an explicit restriction on what kind of GET requests you can make with the API. See fetch.spec.whatwg.org/#ref-for-dom-requestinit-body%E2%91%A0: “If either init["body"] exists and is non-null or inputBody is non-null, and request’s method isGET
orHEAD
, then throw a TypeError.”
– sideshowbarker
Mar 24 at 9:45
add a comment |
It seems like the error message is pretty clear: GET requests can’t have a request body, but your code is trying to send a GET request with anapplication/json
request body. Why are you trying do that? Why aren’t you just using a POST request instead?
– sideshowbarker
Mar 23 at 0:51
Using the POST-request have to lead change back-end legacy code, it is not in my competence. If i will have not solved at next week with FETCH-function, i will code a Promise-wrapper around XMLHttpRequest
– Gerasim Gerasimov
Mar 23 at 4:35
Have you got an idea, how the POSTMAN doing that? get-header. get-body.
– Gerasim Gerasimov
Mar 24 at 6:58
Postman is able to send GET requests that have a request body because like other general HTTP clients there are no restrictions on the characteristics of HTTP requests it can make. But the the case of the Fetch API, the Fetch spec places an explicit restriction on what kind of GET requests you can make with the API. See fetch.spec.whatwg.org/#ref-for-dom-requestinit-body%E2%91%A0: “If either init["body"] exists and is non-null or inputBody is non-null, and request’s method isGET
orHEAD
, then throw a TypeError.”
– sideshowbarker
Mar 24 at 9:45
It seems like the error message is pretty clear: GET requests can’t have a request body, but your code is trying to send a GET request with an
application/json
request body. Why are you trying do that? Why aren’t you just using a POST request instead?– sideshowbarker
Mar 23 at 0:51
It seems like the error message is pretty clear: GET requests can’t have a request body, but your code is trying to send a GET request with an
application/json
request body. Why are you trying do that? Why aren’t you just using a POST request instead?– sideshowbarker
Mar 23 at 0:51
Using the POST-request have to lead change back-end legacy code, it is not in my competence. If i will have not solved at next week with FETCH-function, i will code a Promise-wrapper around XMLHttpRequest
– Gerasim Gerasimov
Mar 23 at 4:35
Using the POST-request have to lead change back-end legacy code, it is not in my competence. If i will have not solved at next week with FETCH-function, i will code a Promise-wrapper around XMLHttpRequest
– Gerasim Gerasimov
Mar 23 at 4:35
Have you got an idea, how the POSTMAN doing that? get-header. get-body.
– Gerasim Gerasimov
Mar 24 at 6:58
Have you got an idea, how the POSTMAN doing that? get-header. get-body.
– Gerasim Gerasimov
Mar 24 at 6:58
Postman is able to send GET requests that have a request body because like other general HTTP clients there are no restrictions on the characteristics of HTTP requests it can make. But the the case of the Fetch API, the Fetch spec places an explicit restriction on what kind of GET requests you can make with the API. See fetch.spec.whatwg.org/#ref-for-dom-requestinit-body%E2%91%A0: “If either init["body"] exists and is non-null or inputBody is non-null, and request’s method is
GET
or HEAD
, then throw a TypeError.”– sideshowbarker
Mar 24 at 9:45
Postman is able to send GET requests that have a request body because like other general HTTP clients there are no restrictions on the characteristics of HTTP requests it can make. But the the case of the Fetch API, the Fetch spec places an explicit restriction on what kind of GET requests you can make with the API. See fetch.spec.whatwg.org/#ref-for-dom-requestinit-body%E2%91%A0: “If either init["body"] exists and is non-null or inputBody is non-null, and request’s method is
GET
or HEAD
, then throw a TypeError.”– sideshowbarker
Mar 24 at 9:45
add a comment |
0
active
oldest
votes
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%2f55304302%2fjs-translate-xmlhttprequest-to-fetch-function-get-failed-to-execute-fetch-o%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f55304302%2fjs-translate-xmlhttprequest-to-fetch-function-get-failed-to-execute-fetch-o%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
It seems like the error message is pretty clear: GET requests can’t have a request body, but your code is trying to send a GET request with an
application/json
request body. Why are you trying do that? Why aren’t you just using a POST request instead?– sideshowbarker
Mar 23 at 0:51
Using the POST-request have to lead change back-end legacy code, it is not in my competence. If i will have not solved at next week with FETCH-function, i will code a Promise-wrapper around XMLHttpRequest
– Gerasim Gerasimov
Mar 23 at 4:35
Have you got an idea, how the POSTMAN doing that? get-header. get-body.
– Gerasim Gerasimov
Mar 24 at 6:58
Postman is able to send GET requests that have a request body because like other general HTTP clients there are no restrictions on the characteristics of HTTP requests it can make. But the the case of the Fetch API, the Fetch spec places an explicit restriction on what kind of GET requests you can make with the API. See fetch.spec.whatwg.org/#ref-for-dom-requestinit-body%E2%91%A0: “If either init["body"] exists and is non-null or inputBody is non-null, and request’s method is
GET
orHEAD
, then throw a TypeError.”– sideshowbarker
Mar 24 at 9:45