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


C# WebHeaderCollection.Add方法代码示例

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


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

示例1: HttpRequestHeader_GetKey_Success

 public void HttpRequestHeader_GetKey_Success()
 {
     WebHeaderCollection w = new WebHeaderCollection();
     w.Add("header1", "value1");
     w.Add("header1", "value2");
     Assert.NotEmpty(w.GetKey(0));
 }
开发者ID:dotnet,项目名称:corefx,代码行数:7,代码来源:WebHeaderCollectionTest.netstandard17.cs

示例2: HttpRequestHeader_ToByteArray_Success

 public void HttpRequestHeader_ToByteArray_Success()
 {
     WebHeaderCollection w = new WebHeaderCollection();
     w.Add("header1", "value1");
     w.Add("header1", "value2");
     byte[] byteArr = w.ToByteArray();
     Assert.NotEmpty(byteArr);
 }
开发者ID:dotnet,项目名称:corefx,代码行数:8,代码来源:WebHeaderCollectionTest.netstandard17.cs

示例3: HttpRequestHeader_Get_Success

 public void HttpRequestHeader_Get_Success()
 {
     WebHeaderCollection w = new WebHeaderCollection();
     w.Add("header1", "value1");
     w.Add("header1", "value2");
     string[] values = w.GetValues(0);
     Assert.Equal("value1", values[0]);
     Assert.Equal("value2", values[1]);
 }
开发者ID:dotnet,项目名称:corefx,代码行数:9,代码来源:WebHeaderCollectionTest.netstandard17.cs

示例4: getHeader

 static WebHeaderCollection getHeader(System.Uri pUri)
 {
     var lHeader = new WebHeaderCollection();
     //lHeader.Add("Host", pUri.Host);
     //lHeader.Add("Get", pUri.PathAndQuery);
     //lHeader.Add("Accept", "*/*");
     lHeader.Add("Cache-Control", "no-cache");
     //lHeader.Add("Connection", "Keep-Alive");
     lHeader.Add("Pragma", "no-cache");
     //lHeader.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
     return lHeader;
 }
开发者ID:Seraphli,项目名称:TheInsectersWar,代码行数:12,代码来源:BreakpointDownload.cs

示例5: TestWebHeaderCollectionAdd

	public void TestWebHeaderCollectionAdd()
	{
		WebHeaderCollection whc = new WebHeaderCollection();
		whc.Add("phony:header");
		whc.Add("some", "stuff");
		try
		{
			whc.Add("nonsenseheader");
			Fail("Add: failed to throw exception for missing colon");
		}
		catch (ArgumentException)
		{
			// So far, so good.
		}
		try
		{
			whc.Add(null);
			Fail("Add: failed to throw exception for null header");
		}
		catch (ArgumentNullException)
		{
			// Still ok...
		}
		try
		{
			whc.Add(null, "theOtherCtor");
			Fail("Add: failed to throw header for null name");
		}
		catch (ArgumentNullException)
		{
			// Onward and upward...
		}
		try
		{
			whc.Add("accept:betterNot");
			Fail("Add: failed to throw exception for restricted header");
		}
		catch (ArgumentException)
		{
			// Add looks good...
		}
	}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:42,代码来源:TestWebHeaderCollection.cs

示例6: HttpRequestHeader_Add_Remove_Success

        public void HttpRequestHeader_Add_Remove_Success()
        {
            WebHeaderCollection w = new WebHeaderCollection();
            w.Add(HttpRequestHeader.Warning, "Warning1");

            Assert.Equal(1, w.Count);
            Assert.Equal("Warning1", w[HttpRequestHeader.Warning]);
            Assert.Equal("Warning", w.AllKeys[0]);

            w.Remove(HttpRequestHeader.Warning);
            Assert.Equal(0, w.Count);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:12,代码来源:WebHeaderCollectionTest.netstandard17.cs

示例7: NameValue_AddEmptyValue_Success

 public void NameValue_AddEmptyValue_Success()
 {
     WebHeaderCollection w = new WebHeaderCollection();
     w.Add("custom", "");
 }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:5,代码来源:WebHeaderCollectionTest.cs

示例8: NameValue_AddEmptyName_Fail

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

示例9: NameValue_AddNullName_Fail

 public void NameValue_AddNullName_Fail()
 {
     WebHeaderCollection w = new WebHeaderCollection();
     Assert.Throws<ArgumentNullException>(() => w.Add(null, "test"));
 }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:5,代码来源:WebHeaderCollectionTest.cs

示例10: NameValue_Add_Success

 public void NameValue_Add_Success()
 {
     WebHeaderCollection w = new WebHeaderCollection();
     w.Add("Accept", "text/json");
 }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:5,代码来源:WebHeaderCollectionTest.cs

示例11: GetHeaders

        // Server API

        internal unsafe static WebHeaderCollection GetHeaders(byte[] memoryBlob, IntPtr originalAddress)
        {
            NetEventSource.Enter(null);

            // Return value.
            WebHeaderCollection headerCollection = new WebHeaderCollection();
            fixed (byte* pMemoryBlob = memoryBlob)
            {
                HTTP_REQUEST* request = (HTTP_REQUEST*)pMemoryBlob;
                long fixup = pMemoryBlob - (byte*)originalAddress;
                int index;

                // unknown headers
                if (request->Headers.UnknownHeaderCount != 0)
                {
                    HTTP_UNKNOWN_HEADER* pUnknownHeader = (HTTP_UNKNOWN_HEADER*)(fixup + (byte*)request->Headers.pUnknownHeaders);
                    for (index = 0; index < request->Headers.UnknownHeaderCount; index++)
                    {
                        // For unknown headers, when header value is empty, RawValueLength will be 0 and 
                        // pRawValue will be null.
                        if (pUnknownHeader->pName != null && pUnknownHeader->NameLength > 0)
                        {
                            string headerName = new string(pUnknownHeader->pName + fixup, 0, pUnknownHeader->NameLength);
                            string headerValue;
                            if (pUnknownHeader->pRawValue != null && pUnknownHeader->RawValueLength > 0)
                            {
                                headerValue = new string(pUnknownHeader->pRawValue + fixup, 0, pUnknownHeader->RawValueLength);
                            }
                            else
                            {
                                headerValue = string.Empty;
                            }
                            headerCollection.Add(headerName, headerValue);
                        }
                        pUnknownHeader++;
                    }
                }

                // known headers
                HTTP_KNOWN_HEADER* pKnownHeader = &request->Headers.KnownHeaders;
                for (index = 0; index < HttpHeaderRequestMaximum; index++)
                {
                    // For known headers, when header value is empty, RawValueLength will be 0 and 
                    // pRawValue will point to empty string ("\0")
                    if (pKnownHeader->pRawValue != null)
                    {
                        string headerValue = new string(pKnownHeader->pRawValue + fixup, 0, pKnownHeader->RawValueLength);
                        headerCollection.Add(HTTP_REQUEST_HEADER_ID.ToString(index), headerValue);
                    }
                    pKnownHeader++;
                }
            }

            NetEventSource.Exit(null);
            return headerCollection;
        }
开发者ID:dotnet,项目名称:corefx,代码行数:58,代码来源:Interop.HttpApi.cs

示例12: GetKey_Success

        public void GetKey_Success()
        {
            const string key = "Accept";
            const string key2 = "Content-Length";
            WebHeaderCollection w = new WebHeaderCollection();

            w.Add(key, "text/plain");
            w.Add(key2, "123");

            Assert.Equal(key, w.GetKey(0));
            Assert.Equal(key2, w.GetKey(1));
        }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:12,代码来源:WebHeaderCollectionTest.cs

示例13: ToString_Success

 public void ToString_Success()
 {
     WebHeaderCollection w = new WebHeaderCollection();
     w.Add("Accept", "text/plain");
     w.Add("Content-Length", "123");
     Assert.Equal(
         "Accept: text/plain\r\nContent-Length: 123\r\n\r\n",
         w.ToString());
 }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:9,代码来源:WebHeaderCollectionTest.cs

示例14: TestWebHeaderCollectionRemove

	public void TestWebHeaderCollectionRemove()
	{
		WebHeaderCollection whc = new WebHeaderCollection();
		whc.Add("some:stuff");
		whc.Remove("some");
		try
		{
			whc.Remove(null);
			Fail("Remove: failed to throw exception for null argument");
		}
		catch (ArgumentNullException)
		{
			// Ok
		}
		try
		{
			whc.Remove("[NotValidHeader?]");
			Fail("Remove: failed to throw exception for invalid header name: '[NotValidHeader?]'");
		}
		catch (ArgumentException)
		{
			// Yep...
		}
		try
		{
			whc.Remove("accept");
			Fail("Remove: failed to throw exception for restricted header 'accept'");
		}
		catch (ArgumentException)
		{
			// Still moving along...
		}
	}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:33,代码来源:TestWebHeaderCollection.cs

示例15: TestWebHeaderCollectionToString

	public void TestWebHeaderCollectionToString()
	{
		WebHeaderCollection whc = new WebHeaderCollection();
		whc.Add("test", "entry");
		whc.Add("more:junk");
		AssertEquals("ToString()","test: entry\r\nmore: junk\r\n",
						whc.ToString());
	}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:8,代码来源:TestWebHeaderCollection.cs


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