React Native之Fetch网络请求-个人笔记

1.fetch get

    var bannersURL = 'http://........';
    fetch(bannersURL)
    .then((response) => response.json())
    .then((responseData) => {
      console.log(responseData);
    })
    .catch((error) => {
      console.warn(error);
    });

2. fetch post

    var loginURL = 'http://........';
    fetch(loginURL, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      body: 'user=18212312345&password=123456'
    })
    .then((response) => response.json())
    .then((responseData) => {
      console.log(responseData);
    })
    .catch((error) => {
      console.warn(error);
    });

或者

  var loginURL = 'http://.......';
  fetch(loginURL, {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      user: '18212312345',
      password: '123456',
    })
   })
   .then((response) => response.json())
   .then((responseData) => {
      console.log(responseData);
    })
   .catch((error) => {
      console.warn(error);
   });

你可能感兴趣的:(React Native之Fetch网络请求-个人笔记)