fetch-api

Using Fetch with Authorization Header and CORS

允我心安 提交于 2019-12-08 19:46:36
问题 I'm trying to get my request to go through to a online game API that I can't seem to get working. I'm using the Fetch API, and some request require Authorization Bearer token , but the request never gets sent with the authorization header. I have tried mode: 'no-cors', credentials: 'include' and obviously putting the Authorization in the header like so header: { 'Authorization': 'Bearer TOKEN' } but the request still does not go with the authorization. Can anyone point me in the right

How to fetch data from API for multiple items in React JS component

梦想与她 提交于 2019-12-08 09:03:23
问题 I am trying fetch data from API in my React JS component. Link to API. This API will populate the number count of each vehicle. The last argument 'audi' corresponds to vehicle make name. I need to fetch that data for 64 different vehicles and create dynamic list items (li) but don't know how to do that. Everything is working except fetchCount function. Here is an example of vehicles data which is imported from '../shared/vehicle_make_and_models' there are total 64 care makes. const veh_data =

POST binary data from browser to JFrog / Artifactory server without using form-data

ぐ巨炮叔叔 提交于 2019-12-08 07:52:22
问题 So we get a file (an image file) in the front-end like so: //html <input type="file" ng-change="onFileChange"> //javascript $scope.onFileChange = function (e) { e.preventDefault(); let file = e.target.files[0]; // I presume this is just a binary file // I want to HTTP Post this file to a server // without using form-data }; What I want to know is - is there a way to POST this file to a server, without including the file as form-data? The problem is that the server I am send a HTTP POST

How can i get errors value inside Promise object which return from Fetch Api?

烈酒焚心 提交于 2019-12-08 02:15:14
问题 I have my fetch request like this. fetch(deafaultUrl + '/v1/users/', { headers: { 'Content-Type': 'application/json' }, method: "POST", body: JSON.stringify(userInfoParams) }) .then(function(response) { console.log(response); console.log(response.json()); // not working never go into this function response.json().then(function(value) { console.log('access promise'); console.log(value); // "Success" }); if (response.status !== 200 && response.status !== 201) { throw new Error("Bad response

Handling authentification to Firebase Database with Fetch in a Service Worker

最后都变了- 提交于 2019-12-07 12:33:42
问题 I'm trying to query a Firebase database from a Service Worker using the Fetch API. However it doesn't work as expected as I can't get authenticated correctly. Basically what I'm trying to do is from origin https://myproject.firebaseapp.com inside a Service Worker I do a call like this : var fetchOptions = {}; fetchOptions.credentials = 'include'; var url = options.messageUrl; var request = new Request('https://myproject.firebaseio.com/user/foobar.json', fetchOptions); messagePromise = fetch

How to return the json response from the fetch API

亡梦爱人 提交于 2019-12-07 12:30:14
问题 I have a function like so: check_auth(){ fetch(Urls.check_auth(), { credentials: 'include', method: 'GET' }).then(response => { if(response.ok) return response.json(); }).then(json => { return json.user_logged_in; }); } And then I try to do this: if(this.check_auth()){ // do stuff } else { // do other stuff } But, this.check_auth() is always undefined . What am I missing here? I thought that within fetch's then() was where the resolved Promise object was therefore I thought that I'd get true

Fetch API cannot load file:///android_asset/www/xx/xxx.json. URL scheme “file” is not supported

谁说我不能喝 提交于 2019-12-07 09:16:17
问题 Using cordova build Android app , and add cordova hot code push plugin to make app update automatically, and using Fetch API to load JSON files which located in current project directory, the problem is when update the app, any JSON files cannot be reload,and throw the error Fetch API cannot load file:///android_asset/www/xx/xxx.json. URL scheme "file" is not supported. How to solve this Fecth error in Android app? Or is there any plugin that need add to my cordova project? 回答1: https:/

React Native Fetch: second promise hanging

 ̄綄美尐妖づ 提交于 2019-12-07 01:45:21
问题 Strange problem with React Native's fetch. It was working previously, not sure what I've changed but it's stopped working. login(data,success,fail){ console.log('doing fb login'); fetch(host+'/api/login?credentials='+data.credentials) .then( (response) => { console.log('got login response'); return response.json(); } ) .then( json => { console.log('got login json'); if(json.result!='fail'){ success(json); } else { fail(json); } return json; }) .catch((error) => { console.warn(error); }); }

fetch error No 'Access-Control-Allow-Origin' header is present on the requested resource

十年热恋 提交于 2019-12-06 22:25:33
问题 I'm using fetch API to get data from other APIs this is my code: var result = fetch(ip, { method: 'get', }).then(response => response.json()) .then(data => { country = data.country_name; let lat = data.latitude; let lon = data.longitude; //fetch weather api with the user country return fetch(`https://api.darksky.net/forecast/efc76f378da9a5bd8bb366a91ec6f550/${lat},${lon}`); }) .then(response => response.json()) .then(data => { // access the data of the weather api console.log(JSON.stringify

Using Fetch API with Promise.all

妖精的绣舞 提交于 2019-12-06 12:39:03
问题 my aim is to fetch data from two URLs and perform an action only when both have come back successfully. On the other hand i want to return an error if either of them fail. I have played around with my code and managed to get the desired effect. My question is, is there a more efficient, succinct way of achieving the same functionality? Helper functions let status = (r) => { if (r.ok) { return Promise.resolve(r) } else { return Promise.reject(new Error(r.statusText)) } } let json = (r) => r