【发布时间】:2011-09-17 18:35:38
【问题描述】:
这是 i 模式代码!当我从 firefox 发送 http 请求时,它工作正常!但是当我尝试使用 https Firefox 回复时:
连接到 mail.yahoo.com 时出错。 SSL 收到一条内容类型未知的记录。 (错误代码:ssl_error_rx_unknown_record_type)
我调试代码,它成功连接到 https 并接收字节,但是当它将它传递到套接字时,它会拒绝:
Tehre 是 8080 上的听众,我的代码是:
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
CookieContainer cookie = new CookieContainer();
if (strClientConnection.Contains("443")) {
strClientConnection = "https://" + strClientConnection.Replace(":443","");
};
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strClientConnection);
request.CookieContainer = cookie;
request.KeepAlive = true;
request.Timeout = 120000;
request.AllowAutoRedirect = true;
request.ReadWriteTimeout = 120000;
request.Method = "POST";
{
using (HttpWebResponse myWebResponse = (HttpWebResponse)request.GetResponse())
{
bool isSuccess = (int)myWebResponse.StatusCode < 299 && (int)myWebResponse.StatusCode >= 200;
if (isSuccess)
{
using (Stream reader = myWebResponse.GetResponseStream())
{
int BytesRead = 0;
Byte[] Buffer = new Byte[32];
int BytesSent = 0;
BytesRead = reader.Read(Buffer, 0, 32);
while (BytesRead != 0)
{
m_sockClient.Send(Buffer, BytesRead, 0);
BytesSent += BytesRead;
BytesRead = reader.Read(Buffer, 0, 32);
}
}
}
}
}
【问题讨论】:
-
听起来您的证书需要修复。如果私钥丢失,您可能需要查看 certutil.exe,了解如何重新分配私钥。
标签: c# sockets ssl proxy https