我正在创建一个基本上只需要将一段XML发送到服务器并返回的应用程序。我遇到了麻烦,但要让它发挥作用并得到非常奇怪的错误
public bool Post(string data)
{
string server="http://my-lan-computer:9091/foo"
bool success = false;
HttpClient client = new HttpClient();
try
{
client.PostAsync(server, new StringContent(data, Encoding.UTF8, "text/xml")).Wait(); //error here
success = true;
} catch { }
return success;
}
我发布的服务器不是localhost,但它是我本地网络上的一台计算机。我深深地嵌套了这个错误:
innerException: {"An error occurred while sending the request."}
innerException: {"Unable to connect to the remote server"}
innerException: {"An attempt was made to access a socket in a way forbidden by its access permissions 123.123.123.123:9091"}
我的应用程序上有互联网客户端功能。我可以通过其他商店应用访问我的本地网络和互联网。我可以在firefox中访问资源获得正确的行为。我没有启用防火墙,也没有阻止这些端口的防病毒
什么可能导致这个模糊的错误?我该如何解决?
答案 0 :(得分:14)
要访问LAN,您必须在应用程序清单中声明Private Network
功能。请注意,这与Internet
功能不同。