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


C# Net.HttpWebResponse类代码示例

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


HttpWebResponse类属于System.Net命名空间,在下文中一共展示了HttpWebResponse类的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: Download

 public static void Download()
 {
     using (WebClient wcDownload = new WebClient())
     {
         try
         {
             webRequest = (HttpWebRequest)WebRequest.Create(optionDownloadURL);
             webRequest.Credentials = CredentialCache.DefaultCredentials;
             webResponse = (HttpWebResponse)webRequest.GetResponse();
             Int64 fileSize = webResponse.ContentLength;
             strResponse = wcDownload.OpenRead(optionDownloadURL);
             strLocal = new FileStream(optionDownloadPath, FileMode.Create, FileAccess.Write, FileShare.None);
             int bytesSize = 0;
             byte[] downBuffer = new byte[2048];
             downloadForm.Refresh();
             while ((bytesSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0)
             {
                 strLocal.Write(downBuffer, 0, bytesSize);
                 PercentProgress = Convert.ToInt32((strLocal.Length * 100) / fileSize);
                 pBar.Value = PercentProgress;
                 pLabel.Text = "Downloaded " + strLocal.Length + " out of " + fileSize + " (" + PercentProgress + "%)";
                 downloadForm.Refresh();
             }
         }
         catch { }
         finally
         {
             webResponse.Close();
             strResponse.Close();
             strLocal.Close();
             extractAndCleanup();
             downloadForm.Hide();
         }
     }
 }
开发者ID:bodiroga,项目名称:Avalon,代码行数:35,代码来源:checkForUpdate.cs

示例3: DisposeObject

 private static void DisposeObject(ref HttpWebRequest request, ref HttpWebResponse response,
     ref Stream responseStream, ref StreamReader reader)
 {
     if (request != null)
     {
         request = null;
     }
     if (response != null)
     {
         response.Close();
         response = null;
     }
     if (responseStream != null)
     {
         responseStream.Close();
         responseStream.Dispose();
         responseStream = null;
     }
     if (reader != null)
     {
         reader.Close();
         reader.Dispose();
         reader = null;
     }
 }
开发者ID:superhappy123,项目名称:Test,代码行数:25,代码来源:WebUrlRead.cs

示例4: HttpResponse

        public HttpResponse(HttpWebResponse httpWebResponse)
        {
            CharacterSet = httpWebResponse.CharacterSet;

            ContentEncoding = httpWebResponse.ContentEncoding;
            ContentLength = httpWebResponse.ContentLength;
            ContentType = httpWebResponse.ContentType;

            //Cookies = httpWebResponse.Cookies;
            Headers = httpWebResponse.Headers;

            //IsFromCache = httpWebResponse.IsFromCache;
            //IsMutuallyAuthenticated = httpWebResponse.IsMutuallyAuthenticated;

            //LastModified = httpWebResponse.LastModified;

            Method = httpWebResponse.Method;
            //ProtocolVersion = httpWebResponse.ProtocolVersion;

            //ResponseUri = httpWebResponse.ResponseUri;
            //Server = httpWebResponse.Server;

            HttpStatusCode = (int)httpWebResponse.StatusCode;
            StatusDescription = httpWebResponse.StatusDescription;
        }
开发者ID:soto,项目名称:EventStore,代码行数:25,代码来源:HttpResponse.cs

示例5: CouchResponse

 public CouchResponse(HttpWebResponse response)
 {
     responseString = response.GetResponseString();
     statusCode = response.StatusCode;
     statusDescription = response.StatusDescription;
     etag = response.Headers["ETag"];
 }
开发者ID:Rychard,项目名称:LoveSeat,代码行数:7,代码来源:CouchResponse.cs

示例6: DisneyPostRequest

        public DisneyPostRequest(String url, AuthToken token, String partySize, String mealPeriod, String searchDate)
        {
            String parameters = "grant_type=assertion&assertion_type=public&client_id=WDPRO-MOBILE.CLIENT-PROD&partySize=" + partySize + "&mealPeriod=" + mealPeriod + "&searchDate=" + searchDate;

            IDisneyReservationRequest disneyRequest = this;
            HttpWebRequest request = disneyRequest.setHeadersWithAuthorization(url, token);
            HttpWebResponse response = disneyRequest.makeReservationRequest(request, parameters);
            try
            {
                _response = response;
                String responseMessage = disneyRequest.returnResponse(response);
                ResponseMessage = responseMessage;
                WebHeaderCollection responseHeaders = response.Headers;
                _reservationUrl = responseHeaders.Get("Location");

            }
            catch (NullReferenceException err)
            {
                Console.WriteLine(err.Message);

            }

            DisneyGetRequest reservationRequest = new DisneyGetRequest(_reservationUrl, token);
            ResponseMessage = reservationRequest.ResponseMessage;
        }
开发者ID:allenmichael,项目名称:DisneyTableReservation,代码行数:25,代码来源:DisneyPostRequest.cs

示例7: NetworkDirectWebResponse

		/// <summary>
		/// Initializes a new instance of the <see cref="NetworkDirectWebResponse"/> class.
		/// </summary>
		/// <param name="requestUri">The request URI.</param>
		/// <param name="response">The response.</param>
		internal NetworkDirectWebResponse(Uri requestUri, HttpWebResponse response)
			: base(requestUri, response) {
			Requires.NotNull(requestUri, "requestUri");
			Requires.NotNull(response, "response");
			this.httpWebResponse = response;
			this.responseStream = response.GetResponseStream();
		}
开发者ID:437072341,项目名称:dotnetopenid,代码行数:12,代码来源:NetworkDirectWebResponse.cs

示例8: NetworkDirectWebResponse

		/// <summary>
		/// Initializes a new instance of the <see cref="NetworkDirectWebResponse"/> class.
		/// </summary>
		/// <param name="requestUri">The request URI.</param>
		/// <param name="response">The response.</param>
		internal NetworkDirectWebResponse(Uri requestUri, HttpWebResponse response)
			: base(requestUri, response) {
			Contract.Requires<ArgumentNullException>(requestUri != null);
			Contract.Requires<ArgumentNullException>(response != null);
			this.httpWebResponse = response;
			this.responseStream = response.GetResponseStream();
		}
开发者ID:enslam,项目名称:dotnetopenid,代码行数:12,代码来源:NetworkDirectWebResponse.cs

示例9: WebResponseEventArgs

        /// <summary>
        /// Initializes a new instance of the <see cref="WebResponseEventArgs"/> class
        /// with the specified web response.
        /// </summary>
        /// <param name="response">The HTTP web response.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="response"/> is <c>null</c>.</exception>
        public WebResponseEventArgs(HttpWebResponse response)
        {
            if (response == null)
                throw new ArgumentNullException("response");

            _response = response;
        }
开发者ID:justinsaraceno,项目名称:openstack.net,代码行数:13,代码来源:WebResponseEventArgs.cs

示例10: AddToCache

 public static CacheMetaData AddToCache(HttpWebResponse resp, string file)
 {
     string md5 = resp.Headers[HttpResponseHeader.ETag].Split(':')[0].Substring(1);
     CacheMetaData meta = new CacheMetaData(resp.ContentLength, md5.ToByteArray());
     meta.Save(file);
     return meta;
 }
开发者ID:aeo24,项目名称:WoWMap,代码行数:7,代码来源:CDNCache.cs

示例11: 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

示例12: 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

示例13: 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

示例14: CheckUpdate

        public static void CheckUpdate()
        {
            kIRCVersionChecker.Init();
            Updater = (HttpWebRequest)HttpWebRequest.Create(update_checkerurl);
            Updater_Response = (HttpWebResponse)Updater.GetResponse();

            if (Updater_Response.StatusCode == HttpStatusCode.OK)
            {
                Rocket.Unturned.Logging.Logger.Log("kIRC: Contacting updater...");
                Stream reads = Updater_Response.GetResponseStream();
                byte[] buff = new byte[10];
                reads.Read(buff, 0, 10);
                string ver = Encoding.UTF8.GetString(buff);
                ver = ver.ToLower().Trim(new[] { ' ', '\r', '\n', '\t' }).TrimEnd(new[] { '\0' });

                if (ver == VERSION.ToLower().Trim())
                {
                    Rocket.Unturned.Logging.Logger.Log("kIRC: This plugin is using the latest version!");
                }
                else
                {
                    Rocket.Unturned.Logging.Logger.LogWarning("kIRC Warning: Plugin version mismatch!");
                    Rocket.Unturned.Logging.Logger.LogWarning("Current version: "+VERSION+", Latest version on repository is " + ver + ".");
                }
            }
            else
            {
                Rocket.Unturned.Logging.Logger.LogError("kIRC Error: Failed to contact updater.");
            }
            Updater.Abort();
            Updater = null;
            Updater_Response = null;
            lastchecked = DateTime.Now;
        }
开发者ID:lavery98,项目名称:Rocket_kIRC,代码行数:34,代码来源:kIRCVersionChecker.cs

示例15: CreatePagSeguroServiceException

        /// <summary>
        /// 
        /// </summary>
        /// <param name="response"></param>
        /// <returns></returns>
        internal static PagSeguroServiceException CreatePagSeguroServiceException(HttpWebResponse response)
        {
            if (response == null)
                throw new PagSeguroServiceException("response answered with null value");

            if (response.StatusCode == HttpStatusCode.OK)
                throw new ArgumentException("response.StatusCode must be different than HttpStatusCode.OK", "response");

            using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
            {
                switch (response.StatusCode)
                {
                    case HttpStatusCode.BadRequest:
                        List<ServiceError> errors = new List<ServiceError>();
                        try
                        {
                            ErrorsSerializer.Read(reader, errors);
                        }
                        catch (XmlException e)
                        {
                            return new PagSeguroServiceException(response.StatusCode, e);
                        }

                        return new PagSeguroServiceException(response.StatusCode, errors);

                    default:
                        return new PagSeguroServiceException(response.StatusCode);
                }
            }
        }
开发者ID:danielwolf14,项目名称:bananasfit-web,代码行数:35,代码来源:HttpURLConnectionUtil.cs


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