WP8 HttpClient"无效端口指定"

时间:2014-04-06 01:33:13

标签: c# windows-phone-8 dotnet-httpclient

我正在尝试在WP8上构建一个应用程序,它将使用来自NuGet包的httpclient从网络服务器下载json数据,但该内容不是托管在标准端口上(85是使用的)。当我尝试下载它时,我得到了#34;无效的端口指定"。我假设这意味着它默认限制为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();
}

1 个答案:

答案 0 :(得分:2)

url

中包含端口信息
HttpResponseMessage response = await client.GetAsync("http://www.bob.com:85/endpoint.json");
相关问题