为什么我的Web API服务器拒绝接受来自Android的电话? [英] Why is my Web API server refusing to accept calls from Android?

查看:161
本文介绍了为什么我的Web API服务器拒绝接受来自Android的电话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从Windows应用程序访问我的Web API服务器没有问题。从Android的,虽然是一个不同的故事

I can access my Web API server from a Windows app without problems. From Android, though, is a different story

为什么会是这样?

时的localhost的使用(以URL)错误的事情?我应该使用的计算机的名称,而不是?

Is "localhost" the wrong thing to use (in the URL)? Should I use the name of the computer instead?

请问字符串(字面通过的的http://本地主机:28642 / API /部门/ getCount将SERIALNUM = 4242 )?必须verbatimized

Does the string (passed literally as "http://localhost:28642/api/Departments/GetCount?serialNum=4242") need to be verbatimized?

什么是一个Windows应用程序调用REST方法,以及Android应用程序调用同一个REST方法之间的差异,这会导致后者失败(连接被拒绝)?

What is the difference between a Windows app calling a REST method, and an Android app calling the same REST method, that would cause the latter to fail (connection refused)?

推荐答案

引用本地主机来称呼你的本地计算机上的Andr​​oid模拟器无法正常工作;你需要使用一个特殊的IP该仿真器将转发到主机。您需要替换本地主机 10.0.2.2 ,按的这个答案

Referencing "localhost" to refer to your local machine doesn't work on the Android emulator; you need to use a special IP which the emulator will forward on to the host machine. You need to replace localhost with 10.0.2.2, as per this answer.

如果您是一个物理设备上测试这个(而不是模拟器),你需要使用你的机器的IP在本地网络上。

If you're testing this on a physical device (rather than the emulator) you'll need to use your machines IP on the local network.

这篇关于为什么我的Web API服务器拒绝接受来自Android的电话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆