首页 > 解决方案 > 在 react-native 上使用令牌访问(发送令牌作为参数)获取 api

问题描述

我有这个链接:

https://link.com/link/  (API)
my token to acces web api is : xxxx
and parameter are  idUser = 1, idCommande = 1
Methode : POST

我如何使用这个令牌 xxxx 从 api 获取数据?

标签: apireact-nativenetworking

解决方案


您可以使用 json.stringify 方法来传递令牌。

fetch('YOUR_URL', {
  method: 'POST',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    idUser : 1,
    idCommande : 1,
  })
})

推荐阅读