2017-03-13 1 views
0

Visual C#でHTTP 2.0要求を送信しようとしています。Visual C#でHTTP 2.0リクエストを送信するには?

最新バージョンの.NET Frameworkを使用しています。エッジブラウザの開発者ツールでは、 'https://www.google.com'のWebサイトがHTTP/2として表示されています。

しかし、以下のコードではHTTPバージョン1.1を投げています。リクエストに関連するUser-Agent文字列を追加しました。私はここで何が欠けていますか?

 string html = string.Empty; 
     string url = @TextBox1.Text; 

     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 
     request.AutomaticDecompression = DecompressionMethods.GZip; 
     request.Accept = "text/html, application/xhtml+xml, image/jxr, */*"; 
     request.UserAgent = @"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393"; 
     request.Method = "GET"; 

     using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) 
     using (Stream stream = response.GetResponseStream()) 
     using (StreamReader reader = new StreamReader(stream)) 
     { 
      html = reader.ReadToEnd(); 
      for (int i = 1; i < response.Headers.Count; ++i) 
      { 
       System.Diagnostics.Debug.WriteLine(response.Headers[i]); 

       String resp = response.Headers[i].ToString(); 
       resp = response.Headers[i-1].ToString() + resp; 
       System.Diagnostics.Debug.WriteLine(response.ProtocolVersion); 
       TextBox2.Text = response.ProtocolVersion.ToString(); 
      } 

     } 
     System.Diagnostics.Debug.WriteLine(html); 

     Console.WriteLine(html); 
    } 
+0

MSDNは1.0と1.1がサポートされていることをここにhttps://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.protocolversion(v=vs.110).aspx言います。 – Evk

答えて

関連する問題