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;








0















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.










share|improve this question
























  • 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 or HEAD, then throw a TypeError.”

    – sideshowbarker
    Mar 24 at 9:45


















0















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.










share|improve this question
























  • 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 or HEAD, then throw a TypeError.”

    – sideshowbarker
    Mar 24 at 9:45














0












0








0


0






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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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 or HEAD, 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











  • 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 or HEAD, 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













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
);



);













draft saved

draft discarded


















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















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현