Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 访问SSL站点_C#_Ssl_Windows Phone 8.1_Win Universal App - Fatal编程技术网

C# 访问SSL站点

C# 访问SSL站点,c#,ssl,windows-phone-8.1,win-universal-app,C#,Ssl,Windows Phone 8.1,Win Universal App,我使用C#和Windows Phone 8.1作为通用工具。 如何访问SSL站点? 我使用此代码发布我的HTTPS uri: public async Task<string> SignIn() { string pageSource = ""; string url = Site.Ecare + Site.GetSubAddress(SubAddress.Login); string formParams = stri

我使用C#和Windows Phone 8.1作为通用工具。 如何访问SSL站点? 我使用此代码发布我的HTTPS uri:

    public async Task<string> SignIn()
    {
        string pageSource = "";
        string url = Site.Ecare + Site.GetSubAddress(SubAddress.Login);
        string formParams = string.Format("username={0}&password={1}", Site.Username, Site.Password);
        formParams = Uri.EscapeUriString(formParams);
        byte[] bytes = Encoding.UTF8.GetBytes(formParams);

        HttpWebRequest request;
        request = (HttpWebRequest)WebRequest.Create(url);

        request.UseDefaultCredentials = true;
        //request.Credentials = CredentialCache.;
        request.Method = "Post";
        request.ContentType = "application/x-www-form-urlencoded";

        using (Stream os = await request.GetRequestStreamAsync())
        {
            os.Write(bytes, 0, bytes.Length);
        }

        try
        {
            HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync();
            pageSource = new StreamReader(response.GetResponseStream()).ReadToEnd();

        }
        catch {  }

        return pageSource;
    }
执行:

Exception:
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

谢谢

您有一个空的
catch
块。捕获异常,并发布异常的完整详细信息。以下是异常:基础连接已关闭:无法为SSL/TLS安全通道建立信任关系。您是否正在访问使用自签名证书的终结点?否,它不是自签名的
Exception:
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.