fetch-api

react-native fetch - request body - Unexpected EOF

我怕爱的太早我们不能终老 提交于 2020-01-30 11:16:28
问题 in my react-native application, I'm trying to make fetch request with body . But, I get error message of unexpected EOF . Actually, the request is made, I mean I can see through backend logs that request is sent, whereas, right after the request, it shows error message. Here is my fetch method. var Url = "https://----------"; return fetch(Url, { method: "POST", headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({'number': '11111111-'}) }) .then

Can one use the Fetch API as a Request Interceptor?

泄露秘密 提交于 2020-01-30 04:59:18
问题 I'm trying to run some simple JS functions after every request to the server with the Fetch API. I've searched for an answer to this question, but haven't found any, perhaps due to the fact that the Fetch API is relative recent. I've been doing this with XMLHttpRequest like so: (function () { var origOpen = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function () { this.addEventListener('load', function () { someFunctionToDoSomething(); }); origOpen.apply(this, arguments); }

Response header not showing

我怕爱的太早我们不能终老 提交于 2020-01-29 20:37:13
问题 I am building a simple web app using ReactJS and create-react-app . I have a backend API set up on Heroku where I can make POST requests. Everything works fine, except: When I make a POST request using fetch API, the response is 100% correct but it only gives me 2 standard headers. I want to get my custom header. I have added expose header in my response and here's the plot twist: When I view the headers from Chrome Inspection Tool or Postman (API tool), it shows all the headers, including my

Requesting blob images and transforming to base64 with fetch API

假装没事ソ 提交于 2020-01-24 06:26:30
问题 I have some images that will be displayed in a React app. I perform a GET request to a server, which returns images in BLOB format. Then I transform these images to base64. Finally, i'm setting these base64 strings inside the src attribute of an image tag. Recently I've started using the Fetch API. I was wondering if there is a way to do the transforming in 'one' go. Below an example to explain my idea so far and/or if this is even possible with the Fetch API. I haven't found anything online

Text response is empty when using fetch

心不动则不痛 提交于 2020-01-21 17:27:27
问题 The following code: fetch('http://localhost:8080/root/1487171054127/k_query_bearer_token', { mode: 'no-cors', credentials: 'include' }) .then(function (response) { return response.text(); }) .then(function (text) { console.log('Request successful', text.length); }) .catch(function (error) { log('Request failed', error) }); is outputting: Request successful 0 If I use curl: curl 'http://localhost:8080/root/1487171054127/k_query_bearer_token' \ -H 'Cookie: JSESSIONID=CviS9IK8pcsqADdP-m0MRXX

Using proxy like fiddler with fetch api

只愿长相守 提交于 2020-01-21 11:39:28
问题 How can I set a proxy using Fetch API. I'm developing a node.js application and I'd like to have a look at the response body of an HTTPS response. I'm using this npm package that uses node http inside: https://www.npmjs.com/package/isomorphic-fetch I tried to set the env variables like: set https_proxy=http://127.0.0.1:8888 set http_proxy=http://127.0.0.1:8888 set NODE_TLS_REJECT_UNAUTHORIZED=0 but it seems to work only with request NPM node module. I always get the following message: http:/

Cannot fetch data from Wikipedia API

早过忘川 提交于 2020-01-21 10:11:45
问题 let dataObj = []; const query = 'marvel'; fetch(`https://en.wikipedia.org/w/api.php?action=query&titles=${query}&prop=revisions&rvprop=content&format=json&formatversion=2`) .then(data => data.json()) .then(data => dataObj.push(data)) .catch(err => console.log(err)); This is the error that I receive: No ' Access-Control-Allow-Origin ' header is present on the requested resource. Origin 'https://s.codepen.io' is therefore not allowed access. If an opaque response serves your needs, set the

React Native Fetch does not render response until after clicking screen

那年仲夏 提交于 2020-01-20 06:47:45
问题 So I've been building an app that uses the Fetch API to make a request. Unfortunately, I think the code shown in the Facebook docs are (may be?) incorrect. Problem When starting the app, Fetch makes a call to a URL to pull JSON data. componentDidMount(){ return fetch(REQUEST_URL) .then((response) => response.json()) .then((responseJson) => { this.setState({ isLoading: false, data: JSON.stringify(responseJson) }) }) .catch((error) => { console.error(error); }); } This is similar to the code

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

孤人 提交于 2020-01-19 03:10:49
问题 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? 回答1: 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

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

我只是一个虾纸丫 提交于 2020-01-19 03:09:07
问题 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? 回答1: 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