【问题标题】:Sending secured REST API request in react native在本机反应中发送安全的 REST API 请求
【发布时间】:2019-01-04 12:56:53
【问题描述】:
  • 我正在使用 React Native 的 'fetch' 方法来调用 REST API。我们如何将请求发送到 React Native 中的安全 API(URL 以“https”开头)?

【问题讨论】:

  • 更改 fetch 方法中的 URL。 const request = new Request('https://example.com', {method: 'POST', body: '{"foo": "bar"}'});

标签: react-native


【解决方案1】:

试试这个

参数

var params = 'user_id=' + res.user_id
params += '&first_name=' + firstName

请求

Content-Type - 根据您的要求设置

fetch(url, {
      method: 'POST',
      headers: {
         'Content-Type': 'application/x-www-form-urlencoded',
         'Authorization': token,
      },
      body: params 
  })
  .then((res) => res.json())
  .then((json) => {
     console.log("RESPONSE:- ", json)
  })
  .catch((err) => {
     console.log("ERROR WEB:- ", err)
  })      

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-08
    • 2014-11-05
    • 1970-01-01
    • 1970-01-01
    • 2019-03-29
    相关资源
    最近更新 更多