当前位置: 首页>>代码示例>>C#>>正文


C# HttpWebResponse.GetResponseStream方法代码示例

本文整理汇总了C#中System.Net.HttpWebResponse.GetResponseStream方法的典型用法代码示例。如果您正苦于以下问题:C# HttpWebResponse.GetResponseStream方法的具体用法?C# HttpWebResponse.GetResponseStream怎么用?C# HttpWebResponse.GetResponseStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.HttpWebResponse的用法示例。


在下文中一共展示了HttpWebResponse.GetResponseStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Create

        public string Create(string url)
        {
            try
            {
                // setup web request to tinyurl
                request = (HttpWebRequest)WebRequest.Create(string.Format(TINYURL_ADDRESS_TEMPLATE, url));
                request.Timeout = REQUEST_TIMEOUT;
                request.UserAgent = USER_AGENT;

                // get response
                response = (HttpWebResponse)request.GetResponse();

                // prase response stream to string
                Stream stream = response.GetResponseStream();
                StreamReader reader = new StreamReader(stream, Encoding.GetEncoding(ENCODING_NAME));

                // convert the buffer into string and store in content
                StringBuilder sb = new StringBuilder();
                while (reader.Peek() >= 0)
                {
                    sb.Append(reader.ReadLine());
                }
                return sb.ToString();
            }
            catch (Exception)
            {
                return null;
            }
        }
开发者ID:TlhanGhun,项目名称:digiTweetSnarlEdition,代码行数:29,代码来源:TinyUrlClient.cs

示例2: GetResponseBody

 private static string GetResponseBody(HttpWebResponse response)
 {
     string responseBody = string.Empty;
     if (response.ContentEncoding.ToLower().Contains("gzip"))
     {
         using (GZipStream stream = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress))
         {
             using (StreamReader reader = new StreamReader(stream))
             {
                 responseBody = reader.ReadToEnd();
             }
         }
     }
     else if (response.ContentEncoding.ToLower().Contains("deflate"))
     {
         using (DeflateStream stream = new DeflateStream(response.GetResponseStream(), CompressionMode.Decompress))
         {
             using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
             {
                 responseBody = reader.ReadToEnd();
             }
         }
     }
     else
     {
         using (Stream stream = response.GetResponseStream())
         {
             using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
             {
                 responseBody = reader.ReadToEnd();
             }
         }
     }
     return responseBody;
 }
开发者ID:chinaboard,项目名称:DoubanSpider,代码行数:35,代码来源:HttpHelper.cs

示例3: HttpWebResponseResult

        /// <summary>
        /// Relays an HttpWebResponse as verbatim as possible.
        /// </summary>
        /// <param name="responseToRelay">The HTTP response to relay.</param>
        public HttpWebResponseResult(HttpWebResponse responseToRelay)
        {
            if (responseToRelay == null) {
                throw new ArgumentNullException("response");
            }

            _response = responseToRelay;

            Stream contentStream;
            if (responseToRelay.ContentEncoding.Contains("gzip")) {
                contentStream = new GZipStream(responseToRelay.GetResponseStream(), CompressionMode.Decompress);
            } else if (responseToRelay.ContentEncoding.Contains("deflate")) {
                contentStream = new DeflateStream(responseToRelay.GetResponseStream(), CompressionMode.Decompress);
            } else {
                contentStream = responseToRelay.GetResponseStream();
            }

            if (string.IsNullOrEmpty(responseToRelay.CharacterSet)) {
                // File result
                _innerResult = new FileStreamResult(contentStream, responseToRelay.ContentType);
            } else {
                // Text result
                var contentResult = new ContentResult();
                contentResult = new ContentResult();
                contentResult.Content = new StreamReader(contentStream).ReadToEnd();
                _innerResult = contentResult;
            }
        }
开发者ID:jonfreeland,项目名称:LogglyJavaScriptProxy,代码行数:32,代码来源:LogglyProxyController.cs

示例4: HttpWebRequestCallbackState

        /// <summary>
        /// Initializes a new instance of the <see cref="HttpWebRequestCallbackState"/> class.
        /// </summary>
        /// <param name="response">The response.</param>
        /// <param name="state">The state.</param>
        public HttpWebRequestCallbackState(HttpWebResponse response, object state)
        {
            StatusCode = response.StatusCode;
            Headers = response.Headers;
            ContentType = response.ContentType.Split(new[] { ';' })[0];
            ContentLength = response.ContentLength;

            var contentEncoding = response.Headers[HttpResponseHeader.ContentEncoding] ?? string.Empty;
            if (contentEncoding.Contains("gzip"))
            {
                ResponseStream = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress);
            }
            else if (contentEncoding.Contains("deflate"))
            {
                ResponseStream = new DeflateStream(response.GetResponseStream(), CompressionMode.Decompress);
            }
            else
            {
                ResponseStream = response.GetResponseStream();
            }

            Log.Debug(m => m("HttpWebRequestCallbackState Ctor statusCode:{0}, contentLength:{1}, contentType:{2}", StatusCode, ContentLength, ContentType));

            State = state;
        }
开发者ID:powerinbox,项目名称:embedly-dotnet,代码行数:30,代码来源:HttpWebRequestCallbackState.cs

示例5: GetHttpWebResponseData

 public static string GetHttpWebResponseData(HttpWebResponse response)
 {
     string data = string.Empty;
     if (response != null)
     {
         StreamReader incomingStreamReader = new StreamReader(response.GetResponseStream());
         data = incomingStreamReader.ReadToEnd();
         incomingStreamReader.Close();
         response.GetResponseStream().Close();
     }
     return data;
 }
开发者ID:Sudhansup,项目名称:WindowsModemManager,代码行数:12,代码来源:WebRequestHelper.cs

示例6: ReadResponseStream

    public override async Task<string> ReadResponseStream(HttpWebResponse response) {

      string result = "";
      Stream stream = (string.Equals(response.Headers[HttpRequestHeader.ContentEncoding], "gzip", StringComparison.OrdinalIgnoreCase)) 
                        ? await Task.Run(() => (response.GetResponseStream().Decompress()) ) 
                        : response.GetResponseStream();
      
      using (var reader = new StreamReader(stream)) {
        result = await reader.ReadToEndAsync();
      }

      return result;
    }
开发者ID:rolkun,项目名称:WP8Kochbuch,代码行数:13,代码来源:PhonePlatformAdapter.cs

示例7: ReadResponseStream

    public override async Task<string> ReadResponseStream(HttpWebResponse response) {
      string result;

      using (var gzipStream =
        (string.Equals(response.Headers["Content-Encoding"], "gzip", StringComparison.CurrentCultureIgnoreCase))
          ? new GZipStream(response.GetResponseStream(), CompressionMode.Decompress)
          : response.GetResponseStream()) {

        using (var sr = new StreamReader(gzipStream)) {
          result = await sr.ReadToEndAsync();
        }
      }

      return result;
    }
开发者ID:rolkun,项目名称:WP8Kochbuch,代码行数:15,代码来源:WindowsPlattformAdapter.cs

示例8: GetContent

 public virtual string GetContent(HttpWebResponse webResp, Encoding encoding)
 {
     string content = null;
       var countTry = 3;
       var repeat = true;
       while (repeat && countTry > 0)
     try
     {
       var responseStream = webResp.GetResponseStream();
       responseStream.ReadTimeout = 8000;
       using (var sr = new StreamReader(responseStream, encoding))
       {
     content = sr.ReadToEnd();
     repeat = false;
       }
     }
     catch (WebException exWeb)
     {
       countTry--;
       File.AppendAllText("log.txt", exWeb.Message + Environment.NewLine);
       File.AppendAllText("log.txt", "++" + Environment.NewLine);
       File.AppendAllText("log.txt", exWeb.Status.ToString() + Environment.NewLine);
       File.AppendAllText("log.txt", "++" + Environment.NewLine);
       File.AppendAllText("log.txt", "GetContent" + Environment.NewLine);
       File.AppendAllText("log.txt", "------" + Environment.NewLine);
       var webReq = GetHttpWebReq(url);
       webResp = GetHttpWebResp(webReq);
     }
       return content;
 }
开发者ID:ruslanruslanruslan,项目名称:Parser,代码行数:30,代码来源:WebClAlwaysNewProxy.cs

示例9: ExtractFromResponse

        private PageInfo ExtractFromResponse(HttpWebResponse response)
        {
            var info = new PageInfo();

            using (var responseStream = response.GetResponseStream())
            {
                var htmlDocument = new HtmlDocument();
                htmlDocument.Load(responseStream);
                htmlDocument.OptionFixNestedTags = true;

                var quote = htmlDocument.DocumentNode
                                        .SelectSingleNode("//body")
                                        .SelectNodes("//p").Where(a => a.Attributes.Any(x => x.Name == "class" && x.Value == "qt"))
                                        .SingleOrDefault();

                var title = htmlDocument.DocumentNode
                                        .SelectSingleNode("//title");

                //Quote might not be found, bash.org doesn't have a 404 page
                if (quote == null || title == null)
                {
                    return null;
                }

                //Strip out any HTML that isn't defined in the WhiteList
                SanitizeHtml(quote);

                info.Quote = quote.InnerHtml;
                info.PageURL = response.ResponseUri.AbsoluteUri;
                info.QuoteNumber = title.InnerHtml;
            }

            return info;
        }
开发者ID:paulduran,项目名称:blaze,代码行数:34,代码来源:BashQDBContentProvider.cs

示例10: HttpResponse

 public HttpResponse(HttpWebRequest con)
 {
     this.con = con;
     this.rsp = (HttpWebResponse)con.GetResponse();
     this.stream = rsp.GetResponseStream();
     this.reader = new StreamReader(stream, Encoding.UTF8);
 }
开发者ID:MasterGao,项目名称:DevWinFormFrame,代码行数:7,代码来源:HttpResponse.cs

示例11: Handle

        public void Handle(HttpWebResponse proxyResponse, HttpResponse contextResponse)
        {
            //add cookie
            //foreach (var cookieName in proxyResponse.Cookies)
            //{
            //    var proxyCookie = proxyResponse.Cookies[cookieName.ToString()];

            //    if(proxyCookie.Name.StartsWith("Proxy_"))
            //        contextResponse.SetCookie(new HttpCookie(proxyCookie.Name, proxyCookie.Value));
            //}
            //contextResponse.SetCookie(new HttpCookie("proxyHost", proxyResponse.ResponseUri.Host));

            //add Content-Type
            contextResponse.ContentType = proxyResponse.ContentType;
            //contextResponse
            //add Content-Length
            //Content-Encoding
            //contextResponse.Headers["Content-Encoding"] = proxyResponse.ContentEncoding;

            //copy stream
            using (Stream responseStream = proxyResponse.GetResponseStream())
            {
                Stream rwStream = RewriteStream(responseStream,proxyResponse.ResponseUri, proxyResponse.ContentType);
                //contextResponse.Headers["Content-Length"] = rwStream.Length.ToString();
                rwStream.CopyToStream(contextResponse.OutputStream);
                rwStream.Close();
            }
        }
开发者ID:steven-shi,项目名称:ChooekiProxy,代码行数:28,代码来源:HttpWebResponseProxy.cs

示例12: ReadResponse

 public virtual string ReadResponse(HttpWebResponse response)
 {
     using (StreamReader reader = new StreamReader(response.GetResponseStream()))
     {
         return reader.ReadToEnd();
     }
 }
开发者ID:santiycr,项目名称:selenium,代码行数:7,代码来源:HttpCommandProcessor.cs

示例13: ExtractResponse

        public static WebResponse ExtractResponse( HttpWebResponse response, string filename )
        {
            WebResponse webResponse = null;
            Stream streamResponse = response.GetResponseStream();

            #if !SILVERLIGHT
            if ( response.ContentEncoding.ToLower().Contains( "deflate" ) )
                streamResponse = new DeflateStream( streamResponse, CompressionMode.Decompress );
            else if ( response.ContentEncoding.ToLower().Contains( "gzip" ) )
                streamResponse = new GZipStream( streamResponse, CompressionMode.Decompress );
            #endif

            StreamReader streamRead = null;
            try
            {
                webResponse = new WebResponse();
                webResponse.ResponseBytes = NetworkUtils.StreamToByteArray( streamResponse );
                webResponse.ResponseString = NetworkUtils.ByteArrayToStr( webResponse.ResponseBytes );

                if ( !string.IsNullOrEmpty( filename ) )
                    MXDevice.File.Save(filename, webResponse.ResponseBytes);
            }
            finally
            {
                // Close the stream object
                if ( streamResponse != null )
                    streamResponse.Close();

                if ( streamRead != null )
                    streamRead.Close();
            }

            return webResponse;
        }
开发者ID:BGCX262,项目名称:zulu-omoto-pos-client-svn-to-git,代码行数:34,代码来源:NetworkUtils.cs

示例14: DownloadFile

        public static bool DownloadFile(Uri url, string destFileName, HttpWebResponse response, CancellationToken? token = null, Action<int> indicateProgress = null)
        {
            using (new ProfileSection("Download file", typeof(WebRequestHelper)))
              {
            ProfileSection.Argument("url", url);
            ProfileSection.Argument("destFileName", destFileName);
            ProfileSection.Argument("response", response);
            ProfileSection.Argument("token", token);
            ProfileSection.Argument("indicateProgress", indicateProgress);

            using (var responseStream = response.GetResponseStream())
            {
              try
              {
            Assert.ArgumentNotNull(responseStream, "responseStream");
            responseStream.ReadTimeout = Settings.CoreWebDownloadTimeoutMinutes.Value * Minute;
            DownloadFile(destFileName, responseStream, token, indicateProgress);

            ProfileSection.Result("Done");
            return true;
              }
              catch (OperationCanceledException)
              {
            FileSystem.FileSystem.Local.File.Delete(destFileName);

            ProfileSection.Result("Canceled");
            return false;
              }
              catch (Exception ex)
              {
            throw new InvalidOperationException("Downloading failed with exception", ex);
              }
            }
              }
        }
开发者ID:Brad-Christie,项目名称:Sitecore-Instance-Manager,代码行数:35,代码来源:WebRequestHelper.cs

示例15: Result

 /// <summary>
 /// Initializes a new instance of the <see cref="MadMimi.Result"/> class.
 /// </summary>
 /// <param name='response'>
 /// An HttpWebResponse which contains the result.
 /// </param>
 public Result(HttpWebResponse response)
 {
     statusCode = response.StatusCode;
     using (StreamReader reader = new StreamReader (response.GetResponseStream ())) {
         body = reader.ReadToEnd ();
     }
 }
开发者ID:madmimi,项目名称:madmimi-dotnet,代码行数:13,代码来源:Result.cs


注:本文中的System.Net.HttpWebResponse.GetResponseStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。