C# 访问SSL站点
我使用C#和Windows Phone 8.1作为通用工具。 如何访问SSL站点? 我使用此代码发布我的HTTPS uri: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
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.