【发布时间】:2013-01-29 21:36:52
【问题描述】:
我正在制作一个应用程序,它基本上只需要将一段 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;
}
我发布到的服务器不是本地主机,而是我本地网络上的一台计算机。我得到这个错误深深地嵌套:
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"}
我的应用程序具有 Internet 客户端功能。我可以通过其他商店应用程序访问我的本地网络和互联网。我可以在 Firefox 中访问资源以获得正确的行为。我没有启用防火墙或防病毒软件来阻止这些端口
什么可能导致这个模糊的错误?我该如何解决?
【问题讨论】:
-
似乎响应可能来自服务器。服务器是什么?是 IIS 吗?某种WCF服务?你能检查一下web.config吗?签入 Fiddler 以比较来自 WinRT 应用程序和成功连接到同一服务的另一个客户端的请求?也许它对请求的http动词或标头有特定要求?
标签: c# .net networking windows-runtime dotnet-httpclient