【问题标题】:SSL certificate cannot be found on Windows Phone 8 emulator在 Windows Phone 8 模拟器上找不到 SSL 证书
【发布时间】:2012-12-16 13:34:48
【问题描述】:

我正在为 WP8 开发程序,该程序从 JSON 中检索数据。连接是安全的(网址以 https 开头)。有时它工作正常,但有时我开始收到异常 System.Net.WebException: The remote server returned an error: NotFound. 对于对所有 https URL 的所有请求,此异常开始显示。对于 http URL,一切正常。网址没问题,在模拟器上用IE打开。 我认为,证书可能存在问题,但为什么有时它会起作用?

public static void SendRequest(string requestUrl, Action<Stream, Exception> callback)
{
    var targetUri = new Uri(requestUrl);
    var request = (HttpWebRequest)WebRequest.Create(targetUri);
    request.Method = "POST";

    request.BeginGetResponse(ar => ProcessResponse(ar, callback), request);
}

public static void ProcessResponse(IAsyncResult callbackResult, Action<Stream, Exception> callback)
{
    try
    {
        var myRequest = (HttpWebRequest)callbackResult.AsyncState;
        var myResponse = (HttpWebResponse)myRequest.EndGetResponse(callbackResult);

        callback(myResponse.GetResponseStream(), null);

        myResponse.Close();
    }
    catch (Exception e)
    {
        callback(Stream.Null, e);
        Debug.WriteLine("Error in RequestHelper.ProcessResponse\nErrorMessage - " + e.Message);
    }
}

更新:问题肯定出在 SSL 证书中。当我尝试在 WebBrowser 控件上打开网页时,我收到一条消息 - “我们在使用此站点的安全证书时遇到问题。”。我点击了“继续访问网站”,但没有任何改变。 该页面仍然可以通过 IE 在模拟器上打开。 我尝试安装证书(从站点导出,并使用 IE 下载。我收到消息,该证书已成功添加。但我仍然在 WebBrowser 控件上有错误消息。 有没有办法安装证书?还是不检查它的有效性?

【问题讨论】:

  • "Remote server returned NotFound" 表明它可能是 HTTP 级别的问题(请求了未知资源),而不是证书相关问题的指示。我建议转储您请求的 URL 并在错误发生时对其进行分析——这将否认或证实我的假设。与 SSL 相关的问题更难跟踪,因为在“远程服务器”上可能“找不到”很多东西(CRL 和 OCSP 响应在检查时无法访问或丢失)。
  • 在帖子中添加了代码。调用 EndGetResponse 时发生错误。这种情况在我看来是模拟器,因为我没有更改请求的 url。它可以正常工作一段时间。在任何构建之后,它都可能被破坏。请求的 URL 不变。
  • 现在,你知道如何在 wp 中查看根 CA 列表吗?我也想知道我的自签名证书是否安装成功。

标签: ssl https ssl-certificate windows-phone windows-phone-8


【解决方案1】:

自签名证书工作正常,但您的证书中需要正确的通用名称 (CN)。 CN 必须与您的服务器域相同

然后你需要导入证书。到你的手机

【讨论】:

  • 你能解释清楚吗?我的自签名证书无效
【解决方案2】:

我在通过https 与服务器通信的两个应用程序中遇到了同样的问题,但我还没有找到解决方法。但我破解了它。当我收到WebException: Remote server not found 时,我将检查ResponseStatusCode 和网络异常的Status,如果Status 不是RequestCancelled(你在快速应用程序切换中获得这种状态)我重复请求。它看起来像这样:

var httpStatusCode = ((HttpWebResponse) webException.Response).StatusCode;
                if (httpStatusCode == HttpStatusCode.NotFound || 
                    httpStatusCode == HttpStatusCode.GatewayTimeout ||
                    httpStatusCode == HttpStatusCode.InternalServerError)
                {
                    if (webException.Status == WebExceptionStatus.UnknownError && !configuration.IsResending)
                    {
                        configuration.IsResending = true;
                        ResendRequest(configuration, successAction);
                        return;
                    }

                    configuration.IsResending = false;
                    throw new ServerTemporaryUnavailabeException();
            }

第二次执行请求没有返回WebException: Not found

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多