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


C# WebHeaderCollection.Remove方法代码示例

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


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

示例1: RemoveRestricted

		public void RemoveRestricted ()
		{
			col = CreateRestrictedHeaders ();

			try {
				col.Add ("Host", "foo");
				col.Remove ("Host");
				Assert.Fail ("#2: should fail according to spec");
			} catch (ArgumentException) {}
		}
开发者ID:nickolyamba,项目名称:mono,代码行数:10,代码来源:WebHeaderCollectionTest.cs

示例2: Custom_AddThenRemove_Success

 public void Custom_AddThenRemove_Success()
 {
     WebHeaderCollection w = new WebHeaderCollection();
     w.Add("name", "value");
     w.Remove("name");
     Assert.Equal(0, w.Count);
 }
开发者ID:rcabr,项目名称:corefx,代码行数:7,代码来源:WebHeaderCollectionTest.cs

示例3: ProcessResponseStream

        private byte[] ProcessResponseStream(HttpRequest request, Stream responseStream, WebHeaderCollection webHeaderCollection)
        {
            responseStream.Position = 0;

            if (responseStream.Length != 0)
            {
                var encoding = webHeaderCollection["Content-Encoding"];
                if (encoding != null)
                {
                    if (encoding.IndexOf("gzip") != -1)
                    {
                        responseStream = new GZipStream(responseStream, CompressionMode.Decompress);

                        webHeaderCollection.Remove("Content-Encoding");
                    }
                    else if (encoding.IndexOf("deflate") != -1)
                    {
                        responseStream = new DeflateStream(responseStream, CompressionMode.Decompress);

                        webHeaderCollection.Remove("Content-Encoding");
                    }
                }
            }

            return responseStream.ToBytes();
        }
开发者ID:drewfreyling,项目名称:NzbDrone,代码行数:26,代码来源:CurlHttpDispatcher.cs

示例4: Custom_RemoveBlankName_Throws

 public void Custom_RemoveBlankName_Throws()
 {
     WebHeaderCollection w = new WebHeaderCollection();
     Assert.Throws<ArgumentNullException>(() => w.Remove(""));
 }
开发者ID:rcabr,项目名称:corefx,代码行数:5,代码来源:WebHeaderCollectionTest.cs

示例5: Custom_RemoveIllegalCharacter_Throws

 public void Custom_RemoveIllegalCharacter_Throws()
 {
     WebHeaderCollection w = new WebHeaderCollection();
     Assert.Throws<ArgumentException>(() => w.Remove("{"));
 }
开发者ID:rcabr,项目名称:corefx,代码行数:5,代码来源:WebHeaderCollectionTest.cs

示例6: ProcessResponseStream

        private byte[] ProcessResponseStream(HttpWebRequest webRequest, Stream responseStream, WebHeaderCollection webHeaderCollection)
        {
            responseStream.Position = 0;

            if (responseStream.Length != 0 && webRequest.AutomaticDecompression != DecompressionMethods.None)
            {
                var encoding = webHeaderCollection["Content-Encoding"];
                if (encoding != null)
                {
                    if (webRequest.AutomaticDecompression.HasFlag(DecompressionMethods.GZip) && encoding.IndexOf("gzip") != -1)
                    {
                        responseStream = new GZipStream(responseStream, CompressionMode.Decompress);

                        webHeaderCollection.Remove("Content-Encoding");
                    }
                    else if (webRequest.AutomaticDecompression.HasFlag(DecompressionMethods.Deflate) && encoding.IndexOf("deflate") != -1)
                    {
                        responseStream = new DeflateStream(responseStream, CompressionMode.Decompress);

                        webHeaderCollection.Remove("Content-Encoding");
                    }
                }
            }

            return responseStream.ToBytes();
        }
开发者ID:nnic,项目名称:Sonarr,代码行数:26,代码来源:CurlHttpClient.cs

示例7: provisionSend

 public string[] provisionSend(string message, string method, string url, WebHeaderCollection headers)
 {
     url = Url + url;
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
     if (null != this.ProxyServer)
         request.Proxy = this.ProxyServer;
     request.Method = method;
     request.Timeout = Timeout * 1000;
     if (headers["Accept"] != null)
     {
         request.Accept = headers["Accept"];
         headers.Remove("Accept");
     }
     if (headers["Connection"] != null)
     {
         request.Connection = headers["Connection"];
         headers.Remove("Connection");
     }
     if (headers["Content-Length"] != null)
     {
         request.ContentLength = Convert.ToInt64(headers["Content-Length"]);
         headers.Remove("Content-Length");
     }
     if (headers["Content-Type"] != null)
     {
         request.ContentType = headers["Content-Type"];
         headers.Remove("Content-Type");
     }
     if (headers["Expect"] != null)
     {
         request.Expect = headers["Expect"];
         headers.Remove("Expect");
     }
     if (headers["If-Modified-Since"] != null)
     {
         request.IfModifiedSince = Convert.ToDateTime(headers["If-Modified-Since"]);
         headers.Remove("If-Modified-Since");
     }
     if (headers["Range"] != null)
     {
         request.AddRange(Convert.ToInt32(headers["Range"]));
         headers.Remove("Range");
     }
     if (headers["Referer"] != null)
     {
         request.Referer = headers["Referer"];
         headers.Remove("Referer");
     }
     if (headers["Transfer-Encoding"] != null)
     {
         request.TransferEncoding = headers["Transfer-Encoding"];
         headers.Remove("Transfer-Encoding");
     }
     if (headers["User-Agent"] != null)
     {
         request.UserAgent = headers["User-Agent"];
         headers.Remove("User-Agent");
     }
     foreach (string key in headers.Keys)
     {
         if (request.Headers[key] != null)
         {
             request.Headers.Set(key, headers[key]);
         }
         else request.Headers.Add(key, headers[key]);
     }
     HttpWebResponse response = null;
     StreamReader reader = null;
     Stream stream = null;
     byte[] bytes = null;
     if (message != null)
     {
         bytes = Encoding.UTF8.GetBytes(message);
         request.ContentLength = bytes.Length;
         try
         {
             stream = request.GetRequestStream();
             stream.Write(bytes, 0, bytes.Length);
         }
         catch (System.Exception e)
         {
             Console.WriteLine(e.Message);
             throw new HttpRPCRequestException("Unable to make http request.");
         }
         finally
         {
             if (stream != null)
             {
                 stream.Close();
             }
         }
     }
     try
     {
         response = (HttpWebResponse)request.GetResponse();
         if (response == null) { return null; }
         reader = new StreamReader(response.GetResponseStream());
         string recv = reader.ReadToEnd();
         string statuscode;
         if (HttpStatusCode.OK == response.StatusCode || HttpStatusCode.ResetContent == response.StatusCode || HttpStatusCode.NoContent == response.StatusCode)
//.........这里部分代码省略.........
开发者ID:exosite-labs,项目名称:clronep,代码行数:101,代码来源:HttpTransport.cs

示例8: MSOXCMAPIHTTP_S01_TC11_HTTPStatusCode

        public void MSOXCMAPIHTTP_S01_TC11_HTTPStatusCode()
        {
            this.CheckMapiHttpIsSupported();

            WebHeaderCollection headers = new WebHeaderCollection();
            CookieCollection cookies = new CookieCollection();
            MailboxResponseBodyBase response;

            #region Send a Connect request type request which misses X-RequestId header.
            HttpStatusCode httpStatusCodeFailed;
            AdapterHelper.ClientInstance = Guid.NewGuid().ToString();
            AdapterHelper.Counter = 1;
            headers = AdapterHelper.InitializeHTTPHeader(RequestType.Connect, AdapterHelper.ClientInstance, AdapterHelper.Counter);
            headers.Remove("X-RequestId");
            this.Adapter.Connect(this.AdminUserName, this.AdminUserPassword, this.AdminUserDN, ref cookies, out response, ref headers, out httpStatusCodeFailed);

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R143");

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R143
            this.Site.CaptureRequirementIfAreEqual<uint>(
                7,
                AdapterHelper.GetFinalResponseCode(headers["X-ResponseCode"]),
                143,
                @"[In X-ResponseCode Header Field] Missing Header (7): The request has a missing required header.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R49");

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R49
            this.Site.CaptureRequirementIfAreEqual<HttpStatusCode>(
                HttpStatusCode.OK,
                httpStatusCodeFailed,
                49,
                @"[In Common Response Format] The server returns a ""200 OK"" HTTP status code when the request failed for all non-exceptional failures.");
            #endregion

            #region Send a valid Connect request type to estabish a Session Context with the server.
            HttpStatusCode httpStatusCodeSucceed;
            AdapterHelper.ClientInstance = Guid.NewGuid().ToString();
            AdapterHelper.Counter = 1;
            headers = AdapterHelper.InitializeHTTPHeader(RequestType.Connect, AdapterHelper.ClientInstance, AdapterHelper.Counter);
            string requestIdValue = headers["X-RequestId"];
            cookies = new CookieCollection();
            this.Adapter.Connect(this.AdminUserName, this.AdminUserPassword, this.AdminUserDN, ref cookies, out response, ref headers, out httpStatusCodeSucceed);
            Site.Assert.AreEqual<uint>(0, uint.Parse(headers["X-ResponseCode"]), "The server should return a Status 0 in X-ResponseCode header if client connect to server succeeded.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R48");

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R48
            this.Site.CaptureRequirementIfAreEqual<HttpStatusCode>(
                HttpStatusCode.OK,
                httpStatusCodeSucceed,
                48,
                @"[In Common Response Format] The server returns a ""200 OK"" HTTP status code when the request succeeds.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R2040");

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R2040
            this.Site.CaptureRequirementIfAreEqual<string>(
                requestIdValue,
                headers["X-RequestId"],
                2040,
                @"[In X-RequestId Header Field] the server MUST return this header [X-RequestId] with the same information in the response back to the client.");
            #endregion

            #region Send a Disconnect request type request to destroy the Session Context.
            this.Adapter.Disconnect(out response);
            #endregion

            #region Send an anonymous request that includes a Connect request type.

            System.Threading.Thread.Sleep(60000);

            HttpStatusCode httpStatusCodeUnauthorized;
            AdapterHelper.ClientInstance = Guid.NewGuid().ToString();
            AdapterHelper.Counter = 1;
            headers = AdapterHelper.InitializeHTTPHeader(RequestType.Connect, AdapterHelper.ClientInstance, AdapterHelper.Counter);
            cookies = new CookieCollection();

            this.Adapter.Connect(string.Empty, string.Empty, string.Empty, ref cookies, out response, ref headers, out httpStatusCodeUnauthorized);
            
            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R1331");

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1331
            this.Site.CaptureRequirementIfAreEqual<HttpStatusCode>(
                HttpStatusCode.Unauthorized,
                httpStatusCodeUnauthorized,
                1331,
                @"[In Common Response Format] The server deviates from a ""200 OK"" HTTP status code for authentication (""401 Access Denied"").");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R36");
        
            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R36
            this.Site.CaptureRequirementIfAreNotEqual<HttpStatusCode>(
                HttpStatusCode.OK,
//.........这里部分代码省略.........
开发者ID:OfficeDev,项目名称:Interop-TestSuites,代码行数:101,代码来源:S01_RequestTypesForMailboxServerEndpoint.cs

示例9: Call

        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary> Method to execute the request, and control the exceptions.</summary>
        /// <remarks>   2012/04/19. SSL Exception control code added.
        /// 2012/04/24. Null body controlled when PostWithout body.</remarks>
        /// <returns>The formated Generic Response. 
        /// If Exception occurs (Http 400,500, timeout etc..), and properly formated exception will be thrown.</returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        private BV_Response Call()
        {
            BV_Response genericResponse = null;

            //CONFIGURING THE REQUEST CALL:---------

            //Setting the Certificate if exists:
            if (certCollection != null)
            {
                request.ClientCertificates = certCollection;
            }

            //Setting the Timeout:
            request.Timeout = Constants.blueviaTimeout;
            //Allowing autoredirect: true by default

            //IN POST CASE(with body), the body and headders must be buildt:
            if (headers!=null)
            {
                WebHeaderCollection headerCollection = new WebHeaderCollection();
                foreach (var pair in headers)
                {
                    headerCollection.Add(pair.Key, pair.Value);
                }
                
                //Setting the Content-Type

                //first if the message is a multipart, setting the boundary in the header
                string contentType = null;
                headers.TryGetValue(HttpTools.ContetTypeKey, out contentType);
                if (contentType.Contains("multipart"))
                {
                    string bodyInString = Encoding.Default.GetString(body);
                    string boundary = bodyInString.Substring(2, bodyInString.IndexOf("\r\n") - 2);
                    contentType = string.Format(contentType, boundary);
                }


                //The content-type header must be setted with the following instruction ...
                request.ContentType = contentType;

                //... so deleting from the headerCollection, to avoid an exception ...
                headerCollection.Remove(HttpTools.ContetTypeKey);
                //... when the whole collection of headers is setted.
                request.Headers.Add(headerCollection);

                if (body != null)
                {
                    request.ContentLength = body.Length;

                    //SENDING THE REQUEST FOR PETITIONS WITH BODY:---------
                    try
                    {
                        using (System.IO.Stream putStream = request.GetRequestStream())
                        {
                            putStream.Write(body, 0, body.Length);
                        }
                    }
                    catch (WebException e)
                    {
                        throw new BlueviaException(
                        "SSL error: Unable to create secure channel: " + e.Message
                        , ExceptionCode.ConnectionErrorException);
                    }
                }
            }

            //SENDING THE REQUEST FOR PETITIONS WITHOUT BODY:---------
            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (WebException e)//Only Bluevia Http Errors will be catched
            {
                response = (HttpWebResponse)e.Response;
            }

            //THE RESPONSE HAS BEEN RECEIVED:---------

            //Checking the response status:
            if(response == null)
            {
                throw new BlueviaException(
                    "Http error: Unable to create secure channel."
                    , ExceptionCode.ConnectionErrorException);
            }
            if ((int)response.StatusCode >= 400) //HTTP Error
            {
                BV_ConnectorException ex = new BV_ConnectorException(
                    response.StatusDescription
                    , Convert.ToString((int)response.StatusCode));
                ex.SetConnectorExceptionAdditionalData(CreateAdditionalData());
                throw ex;
//.........这里部分代码省略.........
开发者ID:poornimanaik,项目名称:Official-Library-.Net,代码行数:101,代码来源:HttpConnector.cs

示例10: UpdateHeaderOrRemoveHeaderIfNull

        /// <summary>
        /// Updates the header remove header if null.
        /// </summary>
        /// <param name="headerCollection">The header collection.</param>
        /// <param name="responseHeader">The response header.</param>
        /// <param name="headerValue">The header value.</param>
        private static void UpdateHeaderOrRemoveHeaderIfNull(WebHeaderCollection headerCollection, string responseHeader, string headerValue)
        {
            if (headerValue == null)
            {
                headerCollection.Remove(responseHeader);
                return;
            }

            headerCollection[responseHeader] = headerValue;
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:16,代码来源:HttpContextServiceHost.cs


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