django rest auth 和 react native 的问题
Problem with django rest auth and react native
我正在尝试使用本机反应前端和 django-rest-auth 后端创建登录页面,但是当我发送请求时:
`login = () => {
fetch('http://myIp/rest-auth/login/', {
method: 'POST',
header: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: this.state.username,
password: this.state.password,
})
})
.then((response) => response.json())
.then((res) => {
if (res.success === true) {
AsyncStorage.setItem('user', res.user)
this.props.navigation.navigate('Profile')
}
else {
alert(res.message)
}
})
}
}`
我的后端 returns:
Unsupported Media Type
我只使用 django-rest-auth api 端点。问题是什么 ?谢谢你的帮助;D
在上面的代码中,您使用了 header
而不是 headers
。请像下面这样更改您的代码。
login = () => {
fetch('http://myIp/rest-auth/login/', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: this.state.username,
password: this.state.password,
})
})
.then((response) => response.json())
.then((res) => {
if (res.success === true) {
AsyncStorage.setItem('user', res.user)
this.props.navigation.navigate('Profile')
}
else {
alert(res.message)
}
})
}
}
我正在尝试使用本机反应前端和 django-rest-auth 后端创建登录页面,但是当我发送请求时:
`login = () => {
fetch('http://myIp/rest-auth/login/', {
method: 'POST',
header: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: this.state.username,
password: this.state.password,
})
})
.then((response) => response.json())
.then((res) => {
if (res.success === true) {
AsyncStorage.setItem('user', res.user)
this.props.navigation.navigate('Profile')
}
else {
alert(res.message)
}
})
}
}`
我的后端 returns:
Unsupported Media Type
我只使用 django-rest-auth api 端点。问题是什么 ?谢谢你的帮助;D
在上面的代码中,您使用了 header
而不是 headers
。请像下面这样更改您的代码。
login = () => {
fetch('http://myIp/rest-auth/login/', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: this.state.username,
password: this.state.password,
})
})
.then((response) => response.json())
.then((res) => {
if (res.success === true) {
AsyncStorage.setItem('user', res.user)
this.props.navigation.navigate('Profile')
}
else {
alert(res.message)
}
})
}
}