C# ssl请求耗时超长

shunyongqing 2013-08-18 04:40:48
原来一直用HttpWebRequest来请求网页,截取数据,现在用SslStream来操作https,但发现在很多问题,耗时特别高,原来就几秒的未时,现在要几十秒,代码还有什么问题呢?



TcpClient tcp = new TcpClient();
try
{
tcp.Connect(Host, Port);
if (tcp.Connected)
{
using (SslStream ssl = new SslStream(tcp.GetStream(), false, new RemoteCertificateValidationCallback(MyFunction.ValidateServerCertificate), null))
{
ssl.AuthenticateAsClient("ServerName", new X509CertificateCollection(), SslProtocols.Tls, false);
if (ssl.IsAuthenticated)
{
ssl.Write(bteSend);
ssl.Flush();
while(true)
{
if (!HeaderText.Contains("\r\n\r\n"))
{
intLen = ssl.Read(headerRc,0,1);
HeaderText += GetEncoding.GetString(headerRc, 0, 1);
}
else
{
intLen = ssl.Read(bteReceive, 0, bteReceive.Length);
ms.Write(bteReceive, 0, intLen);//写入流中
}
if (intLen <= 0) break;
}
}
Console.WriteLine(ms.Length);
ms.Seek(0, SeekOrigin.Begin);
}
}
tcp.Close();
}
catch { }
...全文
158 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
游戏人间 2013-08-21
  • 打赏
  • 举报
回复
HttpWebRequest 也可以请求ssl。

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧