gpt4 book ai didi

c# - 构造 SslStream 的 GET 请求

转载 作者:行者123 更新时间:2023-11-30 20:05:41 25 4
gpt4 key购买 nike

如果这有点暗淡,我深表歉意,但我想通过 sslstream 将类似的内容发送到我已获得安全套接字连接的服务器...

GET /F5Check/qpi/1 HTTP/1.1
Host: *****.com
Connection: keep-alive
Cache-Control: max-age=0
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

我尝试使用字符串生成器

var sb = new StringBuilder();
sb.AppendLine("GET /F5Check/qpi/1 HTTP/1.1");
sb.AppendLine(string.Format("Host: {0}", host));
sb.AppendLine("Connection: keep-alive");
sb.AppendLine("User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5");
sb.AppendLine("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
sb.AppendLine("Accept-Encoding: gzip,deflate,sdch");
sb.AppendLine("Accept-Language: en-US,en;q=0.8");
sb.AppendLine("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3");

然后这样做

//Translate the data.
byte[] sendBuffer = UTF8Encoding.UTF8.GetBytes(sb.ToString());

//Send the data.
requestStream.Write(sendBuffer);

其中 sb 是 stringbuilder 对象!

当我尝试从流中读取时,我根本没有从服务器获得任何响应,很明显服务器无法理解我的愚蠢请求!

我知道我可以使用 webrequest 的变体来做同样的事情,但我尝试这样做有一个特定的原因......

基本上我需要知道要对发送的内容进行编码,以便我可以执行获取请求?

最佳答案

黑暗中的一枪:

尝试将请求的 header Connection 设置为“close”。

关于c# - 构造 SslStream 的 GET 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10948317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com