【问题标题】:react native jwt auth basic api反应原生 jwt auth 基本 api
【发布时间】:2020-02-27 04:52:36
【问题描述】:

他们给我的信息是 API 已经在服务器上 我只能使请求类型为 GET 并且需要不同的参数登录端点需要参数“数据” 带有这些值 {"user": "juan", "userid": "123", "passw": "000"}

我需要知道如何使用我只能发出 GET 请求并需要来自 React Native 的参数的 API 登录() {

fetch (Api/a/login',{
    method: "GET",
    headers: {
    'Content-Type': 'application/json',
        Accept: 'application/json',
        Authorization', 'Basic ' + "here should go a token or parameters"
    //'Authorization', 'Basic ' + base64.encode(this.state.user+ ":" + this.state.userid+ ":" + this.state.password)
    }
body: JSON.stringify({   // I don't know if I need you to wear this "body"
        user: this.state.user,
    userid: this.state.userid,
        password: this.state.password
  }),
}).then((response) => response.json())
  .then((responseData) =>{
      console.log("LoginData:-" + JSON.stringify(responseData));
   }).done();
}

【问题讨论】:

    标签: api react-native jwt-auth


    【解决方案1】:

    你可以这样做:

    const username = "julian";
    const userid = 123;
    const passw = "000";
    
    fetch (`Api/a/login?user=${username}&userid=${userid}&password=${passw}`,{
        method: "GET",
        headers: {
        'Content-Type': 'application/json',
            Accept: 'application/json',
            Authorization', 'Basic ' + "here should go a token or parameters"
        //'Authorization', 'Basic ' + base64.encode(this.state.user+ ":" + this.state.userid+ ":" + this.state.password)
        }
    }).then((response) => response.json())
      .then((responseData) =>{
          console.log("LoginData:-" + JSON.stringify(responseData));
       }).done();
    }
    

    在 URL 中传递参数时,您可以删除正文。

    【讨论】:

    • 谢谢,在身份验证中我必须放 Authorization', 'Basic' + "这里应该放一个令牌或参数" //'Authorization', 'Basic' + base64.encode(this. state.user+ ":" + this.state.userid+ ":" + this.state.password)
    猜你喜欢
    • 2020-12-19
    • 1970-01-01
    • 1970-01-01
    • 2018-02-18
    • 1970-01-01
    • 2020-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多