fetch-api

How to fetch XML with fetch api

前提是你 提交于 2019-11-27 20:27:22
I'm trying to making a weather app that displays the weather and the temperature of many days of the week. I'm currently using openweathermap api for such task, the thing is that the information that I want (that is the date of the weather) only comes in xml format. Since I'm rebuilding it in ES6(ES2015) for academic reasons I wanted to also use the fetch api but since the fetch method parses it, it just delivers an error. so how can i fetch it or mby there is a better way to do it. let apis = { currentWeather: { //get user selected recomendation weather api:"http://api.openweathermap.org/data

When do browsers send the Origin header? When do browsers set the origin to null?

主宰稳场 提交于 2019-11-27 20:15:04
As you can see from this Bugzilla thread (and also ), Firefox does not always send an Origin header in POST requests. The RFC states that it should not be sent in certain undefined "privacy-sensitive" contexts. Mozilla defines those contexts here . What I'd like to know is whether these are the only situations in which Firefox will not send the Origin header. As far as I can tell it also will not send it in cross-origin POST requests (though Chrome and IE will), but I can't confirm that in the documentation. Is it enumerated somewhere that I'm missing? As far as what the specs require, the

fetch - Missing boundary in multipart/form-data POST

血红的双手。 提交于 2019-11-27 18:30:21
thanks for stopping by. I want to send a new FormData() as the body of a POST request using the fetch api the operation looks something like this var formData = new FormData() formData.append('myfile', file, 'someFileName.csv') fetch('https://api.myapp.com', { method: 'POST', headers: { "Content-Type": "multipart/form-data" }, body: formData } ) the problem here is that the boundary, something like boundary=----WebKitFormBoundaryyEmKNDsBKjB7QEqu never makes it into the Content-Type: header it should look like this Content-Type:multipart/form-data; boundary=---

Why is this CORS request failing only in Firefox?

南楼画角 提交于 2019-11-27 17:17:57
问题 I'm implementing CORS with credentials and a preflight request and I'm a bit mystified why the preflight request consistently fails in Firefox 30 but works in Safari (7.0.2) and Chrome 35. I think this issue is different from "Why does the preflight OPTIONS request of an authenticated CORS request work in Chrome but not Firefox?" because I am not getting a 401, but rather a CORS-specific message from the browser client: "Cross-Origin Request Blocked: The Same Origin Policy disallows reading

Cannot load Deezer API resources from localhost with the Fetch API

偶尔善良 提交于 2019-11-27 15:17:10
I'm trying to access the Deezer API from localhost, but I'm keep getting the following error: Fetch API cannot load http://api.deezer.com/search/track/autocomplete?limit=1&q=eminem. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. localhost's response's headers does have Access-Control-Allow-Origin header (Access-Control-Allow

fetch() does not send headers?

一笑奈何 提交于 2019-11-27 12:54:35
问题 I am sending POST request like this from browser: fetch(serverEndpoint, { method: 'POST', mode: 'no-cors', // this is to prevent browser from sending 'OPTIONS' method request first redirect: 'follow', headers: new Headers({ 'Content-Type': 'text/plain', 'X-My-Custom-Header': 'value-v', 'Authorization': 'Bearer ' + token, }), body: companyName }) By the time the request reaches my back-end it does not contain X-My-Custom-Header nor Authorization header. My back-end is Google Cloud function for

fetch(), how do you make a non-cached request?

回眸只為那壹抹淺笑 提交于 2019-11-27 12:33:42
with fetch('somefile.json') , it is possible to request that the file be fetched from the server and not from the browser cache? in other words, with fetch() , is it possible to circumvent the browser's cache? Fetch can take an init object containing many custom settings that you might want to apply to the request, this includes an option called "headers". The "headers" option takes a Header object. This object allows you to configure the headers you want to add to your request. By adding pragma: no-cache and a cache-control: no-cache to your header you will force the browser to check the

Why does Fetch API Send the first PUT request as OPTIONS

走远了吗. 提交于 2019-11-27 09:49:15
I am trying to make a cors PUT request using the vanilla Fetch API When I click my button to send the PUT request, the method on the first request is OPTIONS . It is only when I click the button again, then the method on the request changes to PUT . Why? I understand this is part of the CORS preflight, but is there a way to trigger the preflight manually so the OPTIONS response can be cached? Could this behavior be indicative of a failing promise somewhere? guest271314 See the Fetch Standard , section 4.7. CORS-preflight fetch . Note : This is effectively the user agent implementation of the

fetch retry request (on failure)

倾然丶 夕夏残阳落幕 提交于 2019-11-27 07:46:25
问题 I'm using browser's native fetch API for network requests. Also I am using the whatwg-fetch polyfill for unsupported browsers. However I need to retry in case the request fails. Now there is this npm package whatwg-fetch-retry I found, but they haven't explained how to use it in their docs. Can somebody help me with this or suggest me an alternative? 回答1: From the official fetch docs : fetch('/users') .then(checkStatus) .then(parseJSON) .then(function(data) { console.log('succeeded', data) })

Fetch API, custom request headers, CORS, and cross-origin redirects

≡放荡痞女 提交于 2019-11-27 06:08:38
问题 I need to make an HTTP GET request with custom request headers in-browser and process the result as it streams in. The Fetch API is ideal for this: fetch('https://example.com/resource', { method: 'GET', headers: { 'X-Brad-Test': 'true' }, cache: 'no-store', mode: 'cors' }).then((res) => { const reader = res.body.getReader(); // etc. }); This works quite well. Since there are custom headers, the browser pre-flights the request with an OPTIONS request to /resource . I have configured my server