React Native Get Network data

Source: Internet
Author: User

getMoviesFromApiAsync() {    return fetch(‘http://facebook.github.io/react-native/movies.json‘)      .then((response) => response.json())      .then((responseJson) => { return responseJson.movies; }) .catch((error) => { console.error(error); }); }

You can also use the/syntax in the ES7 standard in the React native app async await :

  // 注意这个方法前面有async关键字  async getMoviesFromApi() {    try {      // 注意这里的await语句,其所在的函数必须有async关键字声明      let response = await fetch(‘http://facebook.github.io/react-native/movies.json‘); let responseJson = await response.json(); return responseJson.movies; } catch(error) { console.error(error); } }

Don't forget fetch to catch an exception that might be thrown, or you might not see any hints when an error occurs.

By default, iOS blocks all non-HTTPS requests. If the interface you are requesting is an HTTP protocol, you first need to add an exception to the app Transport Securty, which you can refer to in detail.

React Native Get Network data

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.