fetch

React native - FETCH - Authorization header not working

岁酱吖の 提交于 2021-02-11 16:48:06
问题 I made a server query via an app developed using react-native. I used fetch API and it turns out any query with authorization header not working. POST and GET method REQUESTS that don't expect Authorization headers at the server side works well. Some Queries at the server side are protected with authorization and when I make such queries including authorization header, I always get '401:unauthorized' error. But such queries works well with POSTMAN. Any suggestions here would be of great help.

React native - FETCH - Authorization header not working

耗尽温柔 提交于 2021-02-11 16:47:26
问题 I made a server query via an app developed using react-native. I used fetch API and it turns out any query with authorization header not working. POST and GET method REQUESTS that don't expect Authorization headers at the server side works well. Some Queries at the server side are protected with authorization and when I make such queries including authorization header, I always get '401:unauthorized' error. But such queries works well with POSTMAN. Any suggestions here would be of great help.

CORS error when using fetch with Content-Type [duplicate]

匆匆过客 提交于 2021-02-11 15:40:54
问题 This question already has answers here : How to add cross domain support to WCF service (4 answers) Closed 7 months ago . i'm trying to send a POST request to a REST web service from a different domain in FireFox. i'm using the JavaScript "fetch" function for this. i'm hosting the REST web service in IIS. it works fine before i add a "Content-Type" header in JavaScript. CORS errors in the FireFox console note that if i enable XHR in the console, then i can see that using fetch with the

Fetch request in class component is not returning data or updating state

风格不统一 提交于 2021-02-11 14:14:56
问题 I have refactored a component to add a fetch request to an AWS database, the data is accessible and a quick mock on codesandbox works. However when used in this context it errors as... TypeError: Cannot read property 'forEach' of undefined Unhandled Rejection (TypeError): this.setState is not a function and in the console... {error: null, isLoaded: true, users: Array(0), undefined} code below... constructor() { this.mapUserCountries = {}; this.state = { error: null, isLoaded: true, users: []

How do I loop through multiple pages in an API?

一世执手 提交于 2021-02-11 13:32:17
问题 I am using the Star Wars API https://swapi.co/ I need to pull in starships information, the results for starships span 4 pages, however a get call returns only 10 results per page. How can I iterate over multiple pages and get the info that I need? I have used the fetch api to GET the first page of starships and then added this array of 10 to my totalResults array, and then created a While loop to check to see if 'next !== null' (next is the next page property in the data, if we were viewing

React-Native; Objects are not valid as a react child

与世无争的帅哥 提交于 2021-02-11 06:09:23
问题 I'm getting an error at dataSource: responseJson.event_array , when I remove this line everything works fine however, when I compare it to other peoples code it's the same. It does reach the server, because I do not get the alert message. componentDidMount() { fetch('valid url') .then((response) => response.json()) .then((responseJson) => { this.setState({ dataSource: responseJson.event_array, isLoading: false }); }) .catch((error) => { alert('Could not reach the server!') }); } What am I

React-Native; Objects are not valid as a react child

て烟熏妆下的殇ゞ 提交于 2021-02-11 06:07:02
问题 I'm getting an error at dataSource: responseJson.event_array , when I remove this line everything works fine however, when I compare it to other peoples code it's the same. It does reach the server, because I do not get the alert message. componentDidMount() { fetch('valid url') .then((response) => response.json()) .then((responseJson) => { this.setState({ dataSource: responseJson.event_array, isLoading: false }); }) .catch((error) => { alert('Could not reach the server!') }); } What am I

React-Native; Objects are not valid as a react child

大城市里の小女人 提交于 2021-02-11 06:05:30
问题 I'm getting an error at dataSource: responseJson.event_array , when I remove this line everything works fine however, when I compare it to other peoples code it's the same. It does reach the server, because I do not get the alert message. componentDidMount() { fetch('valid url') .then((response) => response.json()) .then((responseJson) => { this.setState({ dataSource: responseJson.event_array, isLoading: false }); }) .catch((error) => { alert('Could not reach the server!') }); } What am I

Trying to recreate a Python API call request in JavaScript using Fetch with FormData

隐身守侯 提交于 2021-02-11 05:29:53
问题 So I am trying to recreate an API request in JavaScript as it is currently done in Python. Here is the part of the Python program which matters: self.data = {'id': username, 'pass': password} self.session_id = self.post(base_url + loginURLtemplate, data=self.data).headers So essentially the POST request returns everything I need. It returns a sessionid as well as a connection value of 'Keep-Alive' . This is the same behaviour as in Postman, or the browser. Now when it comes to the JavaScript

Getting html from fetch request

你。 提交于 2021-02-10 20:47:49
问题 I am trying to get the html from an api response. If I execute the following fetch request: const fetchHtml = () => { return fetch('local:8080/api/getHtml') .then((response) => { console.log("Response:"); console.log(response.text()); }) .then((data) => { console.log("Data:"); console.log(data); }); }; }; I get the following console message: Response: Promise {<pending>} __proto__: Promise [[PromiseStatus]]: "resolved" [[PromiseValue]]: "<html><head><title>Your interest in PROGRAM_NAME</