帖子数据本身被转换为原始数据



当Android通过axios在React Native中发送post请求时,数据以raw格式发送到服务器。

RN 0.67.3axios 0.26.0

Server% php 7.1

是什么原因导致的?

我对这个问题有2个想法,但由于你没有添加任何代码到你的问题,我不确定我的答案:

  1. 将您的Axios帖子与Axios中完整的帖子示例进行比较,并使用"Content-Type': 'application/json";
var postData = {
email: "test@test.com",
password: "password"
};
let axiosConfig = {
headers: {
'Content-Type': 'application/json',
"Access-Control-Allow-Origin": "*",
}
};
axios.post('http://<host>:<port>/<path>', postData, axiosConfig)
.then((res) => {
console.log("RESPONSE RECEIVED: ", res);
})
.catch((err) => {
console.log("AXIOS ERROR: ", err);
})
  1. 确保你的路径安全(https)在android中,如果你想通过http发送数据,你必须编辑AndroidManifest.xml:
<manifest 
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:usesCleartextTraffic="true"> 
// ----------------
</application>
</manifest>

最新更新