【发布时间】:2011-09-13 13:33:11
【问题描述】:
在我的 C# Windows 客户端中,我有一个 POST 提交给“母舰”。当然,我希望提交的数据是安全的,所以我付费让 HostGator 为我颁发 SSL 证书。
我保存了 .CER 文件,并且正在构建请求:
//wrapper for WebClient object to use certificate file
class SecureWebClient : WebClient
{
protected override WebRequest GetWebRequest(Uri address)
{
HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
string certPath = @"e:\mycertificate.cer";
X509Certificate myCert = X509Certificate.CreateFromCertFile(certPath);
request.ClientCertificates.Add(myCert);
return request;
}
}
//request
private static SecureWebClient client = new SecureWebClient();
private static NameValueCollection = new NameValueCollection();
nvc.Add(POST_ACTION, ACTION_CODE_LOGIN);
nvc.Add(POST_EMAIL, email);
nvc.Add(POST_PASSWORD, password);
sResponse = System.Text.Encoding.ASCII.GetString(client.UploadValues(BASE_URL + ACTION_PAGE, nvc));
它抛出一个 System.Net.WebException:
底层连接已关闭:发送时发生意外错误。
InnerException 是 System.IO.IOException:
由于意外的数据包格式,握手失败。
任何关于我做错了什么的见解?
【问题讨论】:
-
你想要在客户端还是服务器上的 SSL 证书?
-
澄清一下:你想加密通信吗(你需要服务器上的证书)?还是您想对客户端进行身份验证(您需要客户端证书)?具体来说,您需要在相关端有一个私钥(可能是一个 .PFX 文件)。
-
我并不完全精通安全方法。我可以使用 HTTPS 协议在浏览器中访问主机站点。我想通过加密将数据发布到完全相同的服务器/站点。所以,@SLaks - 从技术上讲,我不确定我想要什么。如上所述,我只是外行知道我需要什么。
-
@Roger - 请参见上文(我只能为每条评论添加 1 个 @ 标签)
标签: c# https httpwebrequest certificate http-post