Read text from response

后端 未结 7 1095
野趣味
野趣味 2020-12-04 23:48
HttpWebRequest request = WebRequest.Create(\"http://google.com\") as HttpWebRequest;  

request.Accept = \"application/xrds+xml\";  
HttpWebResponse response = (Http         


        
相关标签:
7条回答
  • 2020-12-05 00:15

    If you http request is Post and request.Accept = "application/x-www-form-urlencoded"; then i think you can to get text of respone by code bellow:

    var contentEncoding = response.Headers["content-encoding"];
                            if (contentEncoding != null && contentEncoding.Contains("gzip")) // cause httphandler only request gzip
                            {
                                // using gzip stream reader
                                using (var responseStreamReader = new StreamReader(new GZipStream(response.GetResponseStream(), CompressionMode.Decompress)))
                                {
                                    strResponse = responseStreamReader.ReadToEnd();
                                }
                            }
                            else
                            {
                                // using ordinary stream reader
                                using (var responseStreamReader = new StreamReader(response.GetResponseStream()))
                                {
                                    strResponse = responseStreamReader.ReadToEnd();
                                }
                            }
    
    0 讨论(0)
提交回复
热议问题