无法将android React本机应用程序连接到localHost.NET api
我有一个React本机应用程序,只需登录,然后使用返回的access_令牌获取数据。我试图通过连接到运行在localHost:50968上的本地托管的.NET api来调试错误。这是回报无法将android React本机应用程序连接到localHost.NET api,.net,visual-studio,react-native,localhost,react-native-android,.net,Visual Studio,React Native,Localhost,React Native Android,我有一个React本机应用程序,只需登录,然后使用返回的access_令牌获取数据。我试图通过连接到运行在localHost:50968上的本地托管的.NET api来调试错误。这是回报 TypeError: Network request failed 我已经在manifext.xml中启用了internet权限。 大多数谷歌搜索都说我需要将localHost:50968更改为我的ip地址。这是迄今为止使用'192.168.0.2:50968/token最接近的一次,但下面是回应
TypeError: Network request failed
我已经在manifext.xml中启用了internet权限。
大多数谷歌搜索都说我需要将localHost:50968更改为我的ip地址。这是迄今为止使用'192.168.0.2:50968/token最接近的一次,但下面是回应
{ type: 'default',
status: 400,
ok: false,
statusText: undefined,
headers: { map: { 'content-length': [ '334'
],
connection: [ 'close'
],
date: [ 'Thu,
10 Aug201703: 19: 14 GMT'
],
server: [ 'Microsoft-HTTPAPI/2.0'
],
'content-type': [ 'text/html; charset=us-ascii'
]
}
}, url: 'http: //192.168.0.2:50968/token',
_bodyInit:
'<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">\r\n
<HTML>
<HEAD>
<TITLE>Bad Request</TITLE>\r\n
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii">
</HEAD>\r\n
<BODY>
<h2>Bad Request - Invalid Hostname</h2>\r\n
<hr>
<p>HTTP Error 400. The request hostname is invalid.</p>\r\n
</BODY>
</HTML>\r\n', _bodyText: '
<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"> \r\n
<HTML>
<HEAD>
<TITLE>Bad Request
</TITLE>\r\n
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii">
</HEAD>\r\n
<BODY>
<h2>Bad Request - Invalid Hostname</h2>\r\n
<hr>
<p>HTTP Error 400. The request hostname is invalid.</p>\r\n
</BODY>
</HTML>\r\n'}
任何帮助都将不胜感激 使用
10.0.2.2
而不是localhost
http://10.0.2.2:50968/token
在android上,localhost映射到模拟器,而不是您的计算机
希望这有助于使用
10.0.2.2
而不是localhost
http://10.0.2.2:50968/token
在android上,localhost映射到模拟器,而不是您的计算机
希望这有帮助在您发布的回复中,我注意到上面写着
url:'http://192.168.0.2:50968/token'
,在http:
和//code>之间有一个空格。你确定你没有在URL\u LOGIN
中错误地格式化你的URL吗?在你发布的回复中,我注意到上面写着URL:'http://192.168.0.2:50968/token'
,在http:
和//code>之间有一个空格。你确定你没有在URL\u登录时错误地格式化你的URL吗?最终找到了这个。以防其他人有这个问题
我发现最好的方法就是用这个
救了我的命 最终找到了这个。以防其他人有这个问题
我发现最好的方法就是用这个
救了我的命 是的,我试过了。我得到了与使用http://:50968/token时相同的响应是的,我尝试了这个。我得到的响应与使用http://:50968/token时相同。如果您遇到此问题,请使用第二个链接,它是一个救生圈。该工具被Keyoti称为输送机。谢谢你的帮助!使用第二个链接,如果你有这个问题,它是一个救生圈。该工具被Keyoti称为输送机。谢谢你的帮助!
fetch(URL_LOGIN, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
//application/x-www-form-urlencoded
},
body: data
}).then((response) => {
var jsonResponse = JSON.parse(response._bodyInit);
try {
AsyncStorage.setItem('token', jsonResponse.access_token);
loginUserSuccess(dispatch, response)
} catch (error) {
console.log(`Error while saving to Async Storage ${error.message}`)
loginUserFailed(dispatch, error)
}
}).catch(response => {
loginUserFailed(dispatch, response)
});