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


C# HttpWebResponse.GetResponseHeader方法代码示例

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


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

示例1: Response

 internal Response(HttpWebResponse response)
 {
     using (response)
     {
         using (Stream response_stream = response.GetResponseStream())
         {
             if (response_stream.CanRead)
             {
                 byte[] buffer = new byte[16654];
                 int read;
                 using (MemoryStream s = new MemoryStream())
                 {
                     while((read = response_stream.Read(buffer, 0, buffer.Length)) > 0)
                     {
                         s.Write(buffer, 0, read);
                     }
                     Body = new byte[s.Length];
                     s.Seek(0, SeekOrigin.Begin);
                     s.Read(Body, 0, Body.Length);
                 }
             }
         }
         Status = response.StatusCode;
         ContentType = response.GetResponseHeader("Content-Type");
         ETag = response.GetResponseHeader("ETag");
     }
 }
开发者ID:sinm,项目名称:NCouch,代码行数:27,代码来源:Response.cs

示例2: ASOptionsResponse

        public ASOptionsResponse(HttpWebResponse httpResponse)
        {
            // Get the MS-ASProtocolCommands header to determine the
            // supported commands
            commands = httpResponse.GetResponseHeader("MS-ASProtocolCommands");

            // Get the MS-ASProtocolVersions header to determine the
            // supported versions
            versions = httpResponse.GetResponseHeader("MS-ASProtocolVersions");
        }
开发者ID:MishaKharaba,项目名称:ExchangeActiveSync,代码行数:10,代码来源:ASOptionsResponse.cs

示例3: Handle

        public override void Handle(HttpWebResponse web_response)
        {
            string header = web_response.GetResponseHeader("Location");

            if (header != null)
            {
                this._context.Fifa.next_url = header;
            }
            else
                throw new RequestException<SignInPage>("Unable to find Location Header");
        }
开发者ID:ddksaku,项目名称:futbot,代码行数:11,代码来源:SignInPage.cs

示例4: ExtractHeaderFrom

 private static IEnumerable<KeyValuePair<string, string>> ExtractHeaderFrom(HttpWebResponse webResponse)
 {
     return webResponse
         .Headers
         .AllKeys
         .Select(
             headerKey =>
                 new KeyValuePair<string, string>(
                     headerKey,
                     webResponse.GetResponseHeader(headerKey))).ToList();
 }
开发者ID:maplink,项目名称:places-api-client-dotnet,代码行数:11,代码来源:HttpClient.cs

示例5: CopyHeaderValues

 private void CopyHeaderValues(HttpWebResponse response)
 {
     var keys = response.Headers.Keys;
     _headerNames = new string[keys.Count];
     _headers = new Dictionary<string, string>(keys.Count, StringComparer.OrdinalIgnoreCase);
     for (int i = 0; i < keys.Count; i++)
     {
         var key = keys[i];
         var headerValue = response.GetResponseHeader(key);
         _headerNames[i] = key;
         _headers.Add(key, headerValue);
     }
     _headerNamesSet = new HashSet<string>(_headerNames, StringComparer.OrdinalIgnoreCase);
 }
开发者ID:rajdotnet,项目名称:aws-sdk-net,代码行数:14,代码来源:HttpWebRequestResponseData.cs

示例6: Handle

        public override void Handle(HttpWebResponse web_response)
        {
            string header = web_response.GetResponseHeader("Location");

            if (header != null)
            {
                this._context.Fifa.next_url = header;

                if (web_response.Cookies.Count == 0)
                    throw new RequestException<SetPropertys>("Unable to find Cookie Headers");
            }
            else
                throw new RequestException<SetPropertys>("Unable to find Location Header");
        }
开发者ID:ddksaku,项目名称:futbot,代码行数:14,代码来源:SetPropertys.cs

示例7: Handle

        public override void Handle(HttpWebResponse web_response)
        {
            string header = web_response.GetResponseHeader("Location");

            if (header != null)
            {
                this._context.Fifa.next_url = header;

                Cookie cookie = web_response.Cookies["webun"];
                if (cookie != null)
                {
                    if (!cookie.Value.Contains(this._context.Authentication.UserName))
                        throw new RequestException<Login>("Wrong Login Info");
                }
                else
                    throw new RequestException<Login>("Unable to find webun Cookie");

            }
            else
                throw new RequestException<Login>("Unable to find Location Header");
        }
开发者ID:ddksaku,项目名称:futbot,代码行数:21,代码来源:Login.cs

示例8: GetExpiresHeader

        public static DateTime GetExpiresHeader(HttpWebResponse response)
        {
            string expires = response.GetResponseHeader("Expires");
            if (expires != null && expires != String.Empty && expires.Trim() != "-1")
            {
                try
                {
                    DateTime expiresDate = DateTime.Parse(expires, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
                    return expiresDate;
                }
                catch (Exception ex)
                {
                    // look for ANSI c's asctime() format as a last gasp
                    try
                    {
                        string asctimeFormat = "ddd' 'MMM' 'd' 'HH':'mm':'ss' 'yyyy";
                        DateTime expiresDate = DateTime.ParseExact(expires, asctimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces);
                        return expiresDate;
                    }
                    catch
                    {
                    }

                    Trace.Fail("Exception parsing HTTP date - " + expires + ": " + ex.ToString());
                    return DateTime.MinValue;
                }
            }
            else
            {
                return DateTime.MinValue;
            }
        }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:32,代码来源:HttpRequestHelper.cs

示例9: GetWebServiceData

        public string GetWebServiceData(string url)
        {
            lock (this)
            {
                request = HttpWebRequest.Create(url) as HttpWebRequest;
                request.Method = "GET";
                string responseText = null;

                try
                {
                    response = request.GetResponse() as HttpWebResponse;

                    if (request.HaveResponse == true && response == null)
                    {
                        String msg = "response was not returned or is null";
                        throw new WebException(msg);
                    }

                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        String msg = "response with status: " + response.StatusCode + " " + response.StatusDescription;
                        throw new WebException(msg);
                    }

                    // check response headers for the content type
                    string contentType = response.GetResponseHeader("Content-Type");

                    // get the response content
                    StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                    responseText = reader.ReadToEnd();
                    reader.Close();
                    reader.Dispose();

                    // handle failures
                }
                catch (WebException e)
                {
                    if (e.Response != null)
                    {
                        System.Console.Write(response.StatusCode + " " + response.StatusDescription);
                        response = (HttpWebResponse)e.Response;
                    }
                    else
                    {
                        System.Console.Write(e.Message);
                    }

                }
                finally
                {
                    if (response != null)
                    {
                        response.Close();
                    }
                }

                return responseText;
            }
        }
开发者ID:JamesMasterman,项目名称:SeaScan,代码行数:59,代码来源:WebServiceConsumer.cs

示例10: ResponseCallback

 /// <summary>
 /// Initially used via a response callback for commands which expect a async response 
 /// </summary>
 /// <param name="webResponse">the HttpWebResponse that will be sent back to the user from the request</param>
 protected virtual void ResponseCallback(HttpWebResponse webResponse)
 {
     //Track and throw up the X-ms request id (x-ms-request-id)
     MsftAsyncResponseId = webResponse.GetResponseHeader("x-ms-request-id");
     ElastaLogger.MessageLogger.Trace("Hosted Service Response Id: {0}", MsftAsyncResponseId);
     for (;;)
     {
         var asyncCommand = new GetAsyncStatusCommand
                                {
                                    HttpVerb = HttpVerbGet,
                                    SubscriptionId = SubscriptionId,
                                    OperationId = MsftAsyncResponseId,
                                    ServiceType = "operations",
                                    Certificate = Certificate
                                };
         asyncCommand.Execute();
         Thread.Sleep(1000);
         OperationStatus status = asyncCommand.GetOperationStatus();
         switch (status)
         {
             case OperationStatus.InProgress:
                 break;
             case OperationStatus.Failed:
                 ElastaLogger.MessageLogger.Error("Hosted Service Response Id: {0}", MsftAsyncResponseId);
                 SitAndWait.Set();
                 return;
             case OperationStatus.Succeeded:
                 ElastaLogger.MessageLogger.Trace("Hosted Service Response Id: {0}", MsftAsyncResponseId);
                 SitAndWait.Set();
                 return;
         }
     }
 }
开发者ID:AndrewJutton,项目名称:fluent-management,代码行数:37,代码来源:ServiceCommand.cs

示例11: print_log_oa1

        private static void print_log_oa1(HttpWebResponse response)
        {
            Stream streamResponse = response.GetResponseStream();
            StreamReader streamRead = new StreamReader(streamResponse, System.Text.Encoding.GetEncoding(-0));

            string content = response.GetResponseHeader("Set-Cookie");
            session_id = content.Substring(content.IndexOf("JSESSIONID=") + "JSESSIONID=".Length, 32);

            string content_length = response.GetResponseHeader("Content-Length");
            if (content_length == "")
            {
                streamResponse.Close();
                streamRead.Close();
                return;
            }
            if (Int32.Parse(content_length) <= 0)
            {
                streamResponse.Close();
                streamRead.Close();
                return;
            }

            Char[] readBuff = new Char[256];
            int count = streamRead.Read(readBuff, 0, 256);
            Console.WriteLine("The contents of the Html page are.......\n");
            while (count > 0)
            {
                String outputData = new String(readBuff, 0, count);
                Console.Write(outputData);
                count = streamRead.Read(readBuff, 0, 256);
            }
            Console.WriteLine();

            // Close the Stream object.
            streamResponse.Close();
            streamRead.Close();
        }
开发者ID:c-ber,项目名称:cber,代码行数:37,代码来源:Program.cs

示例12: GetStreamForResponse

        /*
        private static Stream GetStreamForResponse(HttpWebResponse webResponse)
        {
            Stream stream;
            switch (webResponse.ContentEncoding.ToUpperInvariant())
            {
                case "GZIP":
                    stream = new GZipStream(webResponse.GetResponseStream(), CompressionMode.Decompress);
                    break;
                case "DEFLATE":
                    stream = new DeflateStream(webResponse.GetResponseStream(), CompressionMode.Decompress);
                    break;

                default:
                    stream = webResponse.GetResponseStream();
                    //stream.ReadTimeout = readTimeOut;
                    break;
            }
            return stream;
        }
        */

		private IOResponse ReadWebResponse(HttpWebRequest webRequest, HttpWebResponse webResponse, IOService service) {
			IOResponse response = new IOResponse ();
            
            
			// result types (string or byte array)
			byte[] resultBinary = null;
			string result = null;
            
			string responseMimeTypeOverride = webResponse.GetResponseHeader ("Content-Type");
            
			using (Stream stream = webResponse.GetResponseStream()) {
				SystemLogger.Log (SystemLogger.Module.CORE, "getting response stream...");
				if (ServiceType.OCTET_BINARY.Equals (service.Type)) {
                    
					int lengthContent = -1;
					if (webResponse.GetResponseHeader ("Content-Length") != null && webResponse.GetResponseHeader ("Content-Length") != "") {
						lengthContent = Int32.Parse (webResponse.GetResponseHeader ("Content-Length"));
					}
					// testing log line
					// SystemLogger.Log (SystemLogger.Module.CORE, "content-length header: " + lengthContent +", max file size: " + MAX_BINARY_SIZE);
					int bufferReadSize = DEFAULT_BUFFER_READ_SIZE;
					if (lengthContent >= 0 && lengthContent<=bufferReadSize) {
						bufferReadSize = lengthContent;
					}
                    
					if(lengthContent>MAX_BINARY_SIZE) {
						SystemLogger.Log (SystemLogger.Module.CORE, 
						                  "WARNING! - file exceeds the maximum size defined in platform (" + MAX_BINARY_SIZE+ " bytes)");
					} else {
						// Read to end of stream in blocks
						SystemLogger.Log (SystemLogger.Module.CORE, "buffer read: " + bufferReadSize + " bytes");
						MemoryStream memBuffer = new MemoryStream ();
						byte[] readBuffer = new byte[bufferReadSize];
						int readLen = 0;
						do {
							readLen = stream.Read (readBuffer, 0, readBuffer.Length);
							memBuffer.Write (readBuffer, 0, readLen);
						} while (readLen >0);
						
						resultBinary = memBuffer.ToArray ();
						memBuffer.Close ();
						memBuffer = null;
					}
				} else {
					SystemLogger.Log (SystemLogger.Module.CORE, "reading response content...");
					using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) {
						result = reader.ReadToEnd ();
					}
				}

			}

			/*************
			 * CACHE
			 *************/

			// preserve cache-control header from remote server, if any
            /*
			string cacheControlHeader = webResponse.GetResponseHeader ("Cache-Control");
			if (cacheControlHeader != null && cacheControlHeader != "") {
				SystemLogger.Log (SystemLogger.Module.CORE, "Found Cache-Control header on response: " + cacheControlHeader + ", using it on internal response...");
				if(response.Headers == null) {
					response.Headers = new IOHeader[1];
				}
				IOHeader cacheHeader = new IOHeader();
				cacheHeader.Name = "Cache-Control";
				cacheHeader.Value = cacheControlHeader;
				response.Headers[0] = cacheHeader;
			}
             */

            
            /*************
			 * HEADERS HANDLING
			 *************/
            if (webResponse.Headers != null)
            {   
                response.Headers = new IOHeader[webResponse.Headers.Count];
//.........这里部分代码省略.........
开发者ID:Appverse,项目名称:appverse-mobile,代码行数:101,代码来源:AbstractIO.cs

示例13: print_log1

        private static void print_log1(HttpWebResponse response)
        {
            Stream streamResponse = response.GetResponseStream();
            StreamReader streamRead = new StreamReader(streamResponse, System.Text.Encoding.GetEncoding(-0));

            string content_length = response.GetResponseHeader("Content-Length");
            if (content_length == "")
            {
                streamResponse.Close();
                streamRead.Close();
                return;
            }
            if (Int32.Parse(content_length) <= 0)
            {
                streamResponse.Close();
                streamRead.Close();
                return;
            }

            string readBuff = streamRead.ReadLine();
            do
            {
                //Console.Write(readBuff);
                //Console.WriteLine();
                search_ip(readBuff);
                readBuff = streamRead.ReadLine();
            } while (!streamRead.EndOfStream);

            // Close the Stream object.
            streamResponse.Close();
            streamRead.Close();
        }
开发者ID:c-ber,项目名称:cber,代码行数:32,代码来源:Program.cs

示例14: ReadResponseHeaders

        /// <summary>
        /// Read headers from the HTTP response and store them into local state.
        /// </summary>
        /// <param name="innerState">
        /// The inner State.
        /// </param>
        /// <param name="response">
        /// The response.
        /// </param>
        private void ReadResponseHeaders(InnerState innerState, HttpWebResponse response)
        {
            string header = response.GetResponseHeader("Content-Disposition");
            if (header != null)
            {
                innerState.HeaderContentDisposition = header;
            }

            header = response.GetResponseHeader("Content-Location");
            if (header != null)
            {
                innerState.HeaderContentLocation = header;
            }

            header = response.GetResponseHeader("ETag");
            if (header != null)
            {
                innerState.HeaderETag = header;
            }

            header = response.GetResponseHeader("Content-Type");
            if (header != null && header != "application/vnd.android.obb")
            {
                throw new StopRequestException(
                    ExpansionDownloadStatus.FileDeliveredIncorrectly, "file delivered with incorrect Mime type");
            }

            string headerTransferEncoding = response.GetResponseHeader("Transfer-Encoding");

            // todo - there seems to be no similar thing in .NET
            // if (!string.IsNullOrEmpty(headerTransferEncoding))
            // {
            header = response.GetResponseHeader("Content-Length");
            if (header != null)
            {
                innerState.HeaderContentLength = header;

                // this is always set from Market
                long contentLength = long.Parse(innerState.HeaderContentLength);
                if (contentLength != -1 && contentLength != this.downloadInfo.TotalBytes)
                {
                    // we're most likely on a bad wifi connection -- we should probably
                    // also look at the mime type --- but the size mismatch is enough
                    // to tell us that something is wrong here
                    Debug.WriteLine("LVLDL Incorrect file size delivered.");
                }
            }

            // }
            // else
            // {
            // // Ignore content-length with transfer-encoding - 2616 4.4 3
            // System.Diagnostics.Debug.WriteLine("DownloadThread : ignoring content-length because of xfer-encoding");
            // }
            Debug.WriteLine("DownloadThread : Content-Disposition: " + innerState.HeaderContentDisposition);
            Debug.WriteLine("DownloadThread : Content-Length: " + innerState.HeaderContentLength);
            Debug.WriteLine("DownloadThread : Content-Location: " + innerState.HeaderContentLocation);
            Debug.WriteLine("DownloadThread : ETag: " + innerState.HeaderETag);
            Debug.WriteLine("DownloadThread : Transfer-Encoding: " + headerTransferEncoding);

            bool noSizeInfo = innerState.HeaderContentLength == null
                              &&
                              (headerTransferEncoding == null
                               || !"chunked".Equals(headerTransferEncoding, StringComparison.OrdinalIgnoreCase));
            if (noSizeInfo)
            {
                throw new StopRequestException(ExpansionDownloadStatus.HttpDataError, "can't know size of download, giving up");
            }
        }
开发者ID:Anomalous-Software,项目名称:Android.Play.ExpansionLibrary,代码行数:78,代码来源:DownloadThread.cs

示例15: HandleRedirect

        /// <summary>
        /// Handle a 3xx redirect status.
        /// </summary>
        /// <param name="state">
        /// The state.
        /// </param>
        /// <param name="response">
        /// The response.
        /// </param>
        /// <param name="statusCode">
        /// The status Code.
        /// </param>
        private void HandleRedirect(State state, HttpWebResponse response, HttpStatusCode statusCode)
        {
            Debug.WriteLine("got HTTP redirect " + statusCode);

            if (state.RedirectCount >= DownloaderService.MaxRedirects)
            {
                throw new StopRequestException(ExpansionDownloadStatus.TooManyRedirects, "too many redirects");
            }

            string header = response.GetResponseHeader("Location");
            if (header == null)
            {
                return;
            }

            Debug.WriteLine("Redirecting to " + header);

            string newUri;
            try
            {
                newUri = new URI(this.downloadInfo.Uri).Resolve(new URI(header)).ToString();
            }
            catch (URISyntaxException)
            {
                Debug.WriteLine("Couldn't resolve redirect URI {0} for {1}", header, this.downloadInfo.Uri);
                throw new StopRequestException(ExpansionDownloadStatus.HttpDataError, "Couldn't resolve redirect URI");
            }

            ++state.RedirectCount;
            state.RequestUri = newUri;
            if ((int)statusCode == 301 || (int)statusCode == 303)
            {
                // use the new URI for all future requests (should a retry/resume be necessary)
                state.NewUri = newUri;
            }

            throw new RetryDownloadException();
        }
开发者ID:Anomalous-Software,项目名称:Android.Play.ExpansionLibrary,代码行数:50,代码来源:DownloadThread.cs


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