Postman 點網核心 API 截圖
Postman 從我的 dot net core API 獲取資料,但我無法使用相同的 API 在 React native 中獲取資料。我嘗試了所有方法,例如更改埠號等。
反應原生 API 請求
useEffect(() => {
const getData= async () => {
try {
const response = await axios.get('http://10.0.2.2:54669/DoctorMaster/Getalldoctorssearch/1062');
setAppointments(response.data);
setIsLoading(false);
console.log(response.data);
} catch (error) {
console.log(error);
}
}
getData()
}, [setAppointments, setIsLoading]);
uj5u.com熱心網友回復:
請遵循以下結構
fetch(
"url"
{
method: "GET",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: "Bearer " JSON.parse(token),
},
}
)
.then((response) => response.json())
.then((responseJson) => {
// Handle response here
})
.catch((error) => {
console.error(error);
});
uj5u.com熱心網友回復:
請注意,React Native 默認拒絕 HTTP 請求而不是 HTTPS 請求:
要在Android中處理 HTTP 請求,請參閱這篇文章
要在iOS中處理 HTTP 請求,請參閱這篇文章
uj5u.com熱心網友回復:
您正在嘗試從移動設備無法獲取 url 的 localhost 獲取資料。您需要在 Web 服務器上發布您的 API,然后您將能夠獲取資料
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/467550.html
標籤:javascript C# 反应 网 反应式
上一篇:將HierarchyId轉換為字串-無法將“System.Byte[]”型別的物件轉換為“System.String”型別
