【问题标题】:Windows 8.1 Windows.Web.HTTP.HTTPClient - Secure to Non Secure Redirect ExceptionWindows 8.1 Windows.Web.HTTP.HTTPClient - 安全到非安全重定向异常
【发布时间】:2014-08-30 22:11:36
【问题描述】:

我正在构建 Windows 8.1 应用程序并使用 Windows.Web.HTTP.HTTPClient API 与自定义 SSO 登录服务进行通信。它从 HTTP 重定向到 HTTP。它在 System.Net.HTTP 上运行良好。 HTTPClient API 但是它对 Windows.Web.HTTP.HTTPClient API 给出了异常。

网址 - https://sso.rumba.int.pearsoncmg.com/sso/loginService?service=http://www.google.com?authservice=rumbasso&username=may23_rumba_edu1&password=pass&gateway=true

我收到异常 - “找不到与此错误代码关联的文本。\r\n\r\n重定向请求会将安全连接更改为非安全连接\r\n”

代码片段

var baseFilter = new HttpBaseProtocolFilter();
baseFilter.AllowAutoRedirect = true;
var httpClient = new HttpClient(baseFilter)
serverURI = new Uri("https://sso.rumba.int.pearsoncmg.com/sso/loginService?service=http://www.google.com?authservice=rumbasso&username=may23_rumba_edu1&password=pass&gateway=true");
HttpResponseMessage response = await httpClient.GetAsync(serverURI);

请告知我可以做些什么来解决这个问题。

【问题讨论】:

    标签: windows-runtime windows-8.1


    【解决方案1】:

    作为一种解决方法,您可以禁用自动重定向并手动执行重定向。

    var filter = new HttpBaseProtocolFilter();
    filter.AllowAutoRedirect = false;
    var client = new HttpClient(filter);
    var response = await client.GetAsync("the url");
    var location = response.Headers["location"];
    response = await client.GetAsync(new Uri(location)).AsTask(cancellationToken, progress);
    return await response.Content.ReadAsBufferAsync();
    

    希望对你有帮助, 如果您找到更智能的解决方案,请告诉我。

    阿尔瓦罗。

    【讨论】:

    • 谢谢阿尔瓦罗。现在我已经改变了我的服务以确保它的安全。因此,现在是 HTTPS 到 HTTPS 重定向,它工作正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-13
    • 2015-03-17
    • 1970-01-01
    • 1970-01-01
    • 2013-07-01
    • 2016-06-16
    相关资源
    最近更新 更多