本文整理汇总了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));
}
示例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);
}
示例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]);
}
示例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;
}
示例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...
}
}
示例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);
}
示例7: NameValue_AddEmptyValue_Success
public void NameValue_AddEmptyValue_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add("custom", "");
}
示例8: NameValue_AddEmptyName_Fail
public void NameValue_AddEmptyName_Fail()
{
WebHeaderCollection w = new WebHeaderCollection();
Assert.Throws<ArgumentException>(() => w.Add("", "test"));
}
示例9: NameValue_AddNullName_Fail
public void NameValue_AddNullName_Fail()
{
WebHeaderCollection w = new WebHeaderCollection();
Assert.Throws<ArgumentNullException>(() => w.Add(null, "test"));
}
示例10: NameValue_Add_Success
public void NameValue_Add_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add("Accept", "text/json");
}
示例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;
}
示例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));
}
示例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());
}
示例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...
}
}
示例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());
}