如何从System.Web.HttpRequest获取协议版本?

时间:2016-11-11 11:43:01

标签: c# asp.net http iis webforms

我有一台Nginx服务器反向代理运行.NET Runtime 4 Web Forms应用程序的IIS服务器。

我试图找出在向IIS发出请求时Nginx使用的HTTP版本(1.0或1.1)。

如何从当前请求中获取HTTP版本?

我已尝试搜索并查看文档。我发现最近的是System.Net.HttpWebRequest的{​​{3}},但HttpRequest没有相同的属性,似乎我无法投出它。

(顺便说一句:我意识到HTTP版本现在很少发生,但它与我正在做的一些调试有关)

2 个答案:

答案 0 :(得分:1)

此值位于Request.Params["SERVER_PROTOCOL"],例如"HTTP/1.1"

答案 1 :(得分:0)

我试图从各种网站上获取和分析扩展信息,我能找到的唯一可持续解决方案是使用Selenium,并遵循以下原则可以获取任何信息,包括协议版本:“ H2”,“ HTTP / 1.1”等

        ChromeOptions options = new ChromeOptions();

        //Following Logging preference helps in enabling the performance logs
        options.SetLoggingPreference("performance", LogLevel.All);

        //Creating Chrome driver instance
        IWebDriver driver = new ChromeDriver(options);
        driver.Navigate().GoToUrl(/*your url goes here*/);

        System.Threading.Thread.Sleep(20000);

        //Extracting the performance logs
        var logs = driver.Manage().Logs.GetLog("performance");
        string str = string.Empty;
        for (int i = 0; i < logs.Count; i++)
        {
            if (logs[i].Message.ToString().IndexOf("\"method\":\"Network.responseReceived\"") > -1 &&
                logs[i].Message.ToString().IndexOf("\"url\":") > -1)
            {
                MessageBox.Show(
                     str.Substring(str.IndexOf("\"protocol\":"), 
                     str.IndexOf(",", str.IndexOf("\"protocol\":")) - str.IndexOf("\"protocol\":"))      
                );
            }
        }

如您所言,您将获得几乎所有可能需要的信息(包括协议版本):

{“ message”:{“ method”:“ Network.responseReceived”,“ params”:{“ frameId”:“ 755A984985C3F1263469B348C78A4AA5”,“ loaderId”:“ 2116D4C83A7C6EFD017CC5BC6814FCAB”,“ requestId”“”“ A” “:{” connectionId“:41,” connectionReused“:false,” encodedDataLength“:9595,” fromDiskCache“:false,” fromPrefetchCache“:false,” fromServiceWorker“:false,” headers“:{” cache-control“: “没有缓存, 必须重新验证”,“内容编码”:“ gzip” ,“内容语言”:“ en”,“内容类型”:“ text / html; charset = utf-8“,” date“:” Sun,2020年4月19日格林尼治标准时间“,” expires“:” Sun, 1978年11月19日05:00:00 GMT”,“服务器”:“ nginx”,“状态”:“ 200”,“变化”:“接受编码”,“ x内容类型选项”:“ nosniff \ nnosniff”,“ x帧” options“:” SAMEORIGIN“,” x-generator“:” Drupal 7 ({http://drupal.org)“,” x-by-by“:” PleskLin“},” mimeType“:” text / html“,”协议“:” h2“ ,” remoteIPAddress“ :“ 195.210.46.29”,“ remotePort”:443,“ requestHeaders”:{“:authority”:“ www.WEBSITENAME.com”,“:method”:“ GET”,“:path”:“ /”,“ :scheme“:” https“,” accept“:” text / html,application / xhtml + xml,application / xml; q = 0.9,image / webp,image / apng, / ; q = 0.8,application / signed-exchange; v = b3; q = 0.9“,” accept-encoding“:” gzip, 放气 br“,” accept-language“:” zh-cn,en; q = 0.9“,” sec-fetch-dest“:” document“,” sec-fetch-mode“:” navigate“,” sec-fetch- site“:” none“,” sec-fetch-user“:”?1“,” upgrade-insecure-requests“:” 1“,” user-agent“:” Mozilla / 5.0 (Windows NT 10.0; Win64; x64)AppleWebKit / 537.36(KHTML,如Gecko) 镀铬/81.0.4044.113 Safari / 537.36“},” securityDetails“:{” certificateId“:0,” certificateTransparencyCompliance“:” Compliance“,” cipher“:” AES_128_GCM“,” issuer“:”让我们 加密权限 X3“,” keyExchange“:” ECDHE_RSA“,” keyExchangeGroup“:” P-256“,” protocol“:” TLS 1.2“,” signedCertificateTimestampList“:[{” hashAlgorithm“:” SHA-256“,” logDescription“:”让我们 加密“ Oak2020” log“,” logId“:” E712F2B0377E1A62FB8EC90C6184F1EA7B37CB561D11265BF3E0F34BF241546E“,” origin“:”嵌入式 在 证书 “ ”signatureAlgorithm“: ”ECDSA“, ”signatureData“: ”30440220600B7A7DE2155D200AE2179CE5E297DC6AB9118E57934440C20E25E33C420ADC02201DC0B323CDCA6BF85100E4816B1405BA5BBB2F41EB225CABCBA4CB5C0513E449“, ”状态“: ”已验证“, ”时间戳“:1.586426567863e + 12},{ ”的HashAlgorithm“: ”SHA-256“,” logDescription “:“谷歌 'Argon2020' log“,” logId“:” B21E05CC8BA2CD8A204E8766F92BB98A2520676BDAFA70E7B249532DEF8B905E“,”原点“:”嵌入式 在 证书 “ ”signatureAlgorithm“: ”ECDSA“, ”signatureData“: ”3046022100AF260074C39A0F1294C8038BAEE0B85F984C7EC80D10203D6AAAC1BB8B5CDF1D022100ECE351015B9375A3F85CA84EC5CB606A5453AF34AFFDC25C5D32BC938A01FD67“, ”状态“: ”已验证“, ”时间戳“:1.586426567862e + 12}], ”主旨名称“: ”WEBSITENAME.com“,” validFrom “:1586422967,” validTo“:1594198967},” securityState“:” secure“,” status“:200,” statusText“:”“,” timing“:{” connectEnd“:399.532,” connectStart“:163.118,” dnsEnd“:163.118,” dnsStart“:163.073,” proxyEnd“:-1,” proxyStart“:-1,” pushEnd“:0,” pushStart“:0,” receiveHeadersEnd“:2137.345,” requestTime“:51622.890236,” sendEnd“:399.969,” sendStart“:399.759,” sslEnd“:399.526,” sslStart“:281.492,” workerReady“:-1,” workerStart“:-1},” url“:” https://www.WEBSITENAME.com/“} ,“时间戳”:51625.02969,“类型”:“文档”}},“网络视图”:“ 755A984985C3F1263469B348C78A4AA5”}