目前我正在做一个个人项目。我创建了一个 express js api 和简单的 React Native 应用程序。当尝试获取一个简单的 json 表单时,我的 api 应用程序失败。我不知道是什么问题?
App.js(反应原生应用)
import React, { useState } from 'react';
import { Button, StyleSheet, Text, View } from 'react-native';
import globalStyles from "./styles/globalStyles";
export default function App() {
const [na, setNa] = useState("Başlık");
const getTestAPI = async () => {
try {
let response = await fetch(
'192.168.1.23:3000/api/getTest', {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
}
);
let json = await response.json();
return json;
} catch (error) {
console.error(error);
}
};
const get = () => {
console.log(getTestAPI.title);
console.log(getTestAPI());
setNa(getTestAPI.title);
};
return (
<View style={globalStyles.container}>
<Text onPress={get} >Değerler : {na}</Text>
<Text>cREATED BY FANTA</Text>
</View>
);
}
server.js (EXPRESS JS API)
// localhost:3000/api/get
router.get("/getTest", (req, res) => {
res.json({"title":"Welcome to the test api get route"});
});
错误