const requestOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
"username": "mukesh",
"password": "1234"
})
};
var url = 'http://ewayswork.com:9000/customer/'
fetch(url, requestOptions)
.then(response => response.json())
.then(data => {
console.log(data)
})
.catch(function(error) {
console.log('Problem with your fetch operation: ' + error.message);
});
这里有一种可能性。
当你使用react native时,你必须使用模拟器或真实设备来检查你的应用程序。
在这两种情况下,如果使用localhost
,则无法访问API。相反,您需要在本地ip地址上运行服务器。
要获取该信息,请转到设置>gt;网络>gt;wifi>gt;你的连接无线网络。在底部,复制ipv4 address
。
然后,在该ipad上运行服务器,并相应地更改您的url。
例如
如果您使用的是django_rest_framework,则在本地ip地址上运行服务器;
python manage.py runserver <Your ip address>
打开Cmd并键入:ipconfig,检查ipv4是否与您放入url的ip相同(不要使用localhost,而是使用您的ip(。