他们提供给我的信息是该API已经在服务器上 而且我只能使请求的类型为GET,并且需要不同的参数,登录端点需要参数“ data” 带有这些值{“ user”:“ juan”,“ userid”:“ 123”,“ passw”:“ 000”}
我需要知道如何使用只能发出GET请求并且需要来自React Native的参数的API login(){
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();
}
答案 0 :(得分:0)
您可以执行以下操作:
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中传递参数时,您可以删除正文。