[英]WP8 HttpClient “Invalid Port Specified”
我正在尝试在WP8上构建一个应用程序,该应用程序将使用NuGet包中的httpclient从Web服务器下载json数据,但是该内容未托管在标准端口上(使用的是85)。 尝试下载时,显示“指定的端口无效”。 我假设这意味着默认情况下它限制为80、8080、443或8443,但是我希望有某种方法可以使其在非标准的Web端口上工作。 我在Windows 8 Metro应用程序中也有同样的事情。 关于如何解决它的任何建议? 只是预先声明,不,我不能更改服务器端的端口。
HttpClientHandler handler = new HttpClientHandler();
handler.Credentials = new NetworkCredential(App.UserName, App.Password);
handler.UseDefaultCredentials = false;
handler.AllowAutoRedirect = true;
HttpClient client = new HttpClient(handler);
HttpResponseMessage response = await client.GetAsync(url);
if (response.StatusCode != System.Net.HttpStatusCode.OK)
{
MessageBoxResult result = MessageBox.Show("Error accessing server. " + response.StatusCode.ToString(), "Server access failure", MessageBoxButton.OKCancel);
return "";
}
else
{
return await response.Content.ReadAsStringAsync();
}
在url
包括端口信息。
HttpResponseMessage response = await client.GetAsync("http://www.bob.com:85/endpoint.json");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.