【发布时间】:2020-02-21 17:54:13
【问题描述】:
我正在构建一个请求 laravel php api 的反应原生应用程序帖子。它适用于邮递员,但不适用于 Axios。你知道我该如何解决吗?我无法发布表单数据
我尝试了其他形式发送 Axios 的 post 请求。但它们都不是解决方案
axios({
method: 'post',
url: 'URL',
params: {
"api_token": token,
"name": "talha"
},
headers: {
Accept: 'application/json',
'Content-Type': 'multipart/form-data'
}
}).then(response => alert(response)).catch(err => console.warn(err))
-----
const serverURL = "URL";
const http = axios.create({
timeout: 1000,
baseURL: serverURL,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
withCredentials: false,
cache: false,
dataType: "jsonp"
});
data is a formdata
await http.post("/passengers", data, config)
.then(Response => alert(Response.data))
.catch(error => console.warn("hata", error))
-----
axios.post( 'URL',
data,
{
headers: {
Accept: 'application/json',
'Content-Type': 'multipart/form-data'
}
}
).then(function(){
alert('SUCCESS!!');
})
.catch(function(){
alert('FAILURE!!');
});
邮递员脚本:
【问题讨论】:
-
你能发布邮递员脚本吗?
-
不。我得到同样的错误 401
-
让它在邮递员中工作并提供详细信息
-
向 api 发送一些参数和标头。我已经将它们添加到代码中。但我给出了 401 错误
-
请生成可以工作的邮递员脚本并在此处发布
标签: laravel react-native networking axios