本文整理汇总了C#中System.Net.WebHeaderCollection.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# WebHeaderCollection.Clear方法的具体用法?C# WebHeaderCollection.Clear怎么用?C# WebHeaderCollection.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebHeaderCollection
的用法示例。
在下文中一共展示了WebHeaderCollection.Clear方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindStreamTest
public void FindStreamTest()
{
// モックの設定
var factory = new MockWebClientFactory();
var mock = factory.MockClient;
mock.Setup(client => client.DownloadString("http://livetube.cc/hakusai/somesbroadcast")).Returns("<html>\r\nvar comment_entry_id = \"somestreamid\";\r\n</html>\r\n");
WebHeaderCollection reqHead = new WebHeaderCollection();
mock.Setup(client => client.Headers).Returns(reqHead);
WebHeaderCollection resHead = new WebHeaderCollection();
resHead.Add("Set-Cookie", "SomeCookie");
mock.Setup(client => client.ResponseHeaders).Returns(resHead);
// 実際の呼び出し
LivetubeClient livetube = new LivetubeClient(factory);
Assert.True(livetube.Login("hakusai", "password"));
reqHead.Clear();
resHead.Clear();
Assert.AreEqual("somestreamid", livetube.FindStream("http://livetube.cc/hakusai/somesbroadcast"));
reqHead.Clear();
resHead.Clear();
livetube.Logoff();
// 結果の確認
Assert.AreEqual("SomeCookie", reqHead["Cookie"]);
mock.Verify(client => client.DownloadString("http://livetube.cc/logoff"));
livetube.Dispose();
}
示例2: PostCommentTest
public void PostCommentTest()
{
// モックの設定
var factory = new MockWebClientFactory();
var mock = factory.MockClient;
mock.Setup(client => client.DownloadString("http://livetube.cc/hakusai/somesbroadcast")).Returns("<html>\r\nvar comment_entry_id = \"somestreamid\";\r\n</html>\r\n");
WebHeaderCollection reqHead = new WebHeaderCollection();
mock.Setup(client => client.Headers).Returns(reqHead);
WebHeaderCollection resHead = new WebHeaderCollection();
resHead.Add("Set-Cookie", "SomeCookie");
mock.Setup(client => client.ResponseHeaders).Returns(resHead);
// 実際の呼び出し
LivetubeClient livetube = new LivetubeClient(factory);
Assert.True(livetube.Login("hakusai", "password"));
reqHead.Clear();
resHead.Clear();
var streamid = livetube.FindStream("http://livetube.cc/hakusai/somesbroadcast");
reqHead.Clear();
resHead.Clear();
livetube.PostComment(streamid, "hakusai", "コメント");
// 結果の確認
Assert.AreEqual("application/x-www-form-urlencoded", reqHead["Content-Type"]);
Assert.AreEqual("SomeCookie", reqHead["Cookie"]);
byte[] bytes = Encoding.ASCII.GetBytes("name=hakusai&c=%E3%82%B3%E3%83%A1%E3%83%B3%E3%83%88");
mock.Verify(client => client.UploadData("http://livetube.cc/stream/somestreamid.comments", "POST", bytes));
reqHead.Clear();
resHead.Clear();
livetube.Logoff();
livetube.Dispose();
}
示例3: LoginTest2_twice
public void LoginTest2_twice()
{
// モックの設定
var factory = new MockWebClientFactory();
var mock = factory.MockClient;
WebHeaderCollection reqHead = new WebHeaderCollection();
mock.Setup(client => client.Headers).Returns(reqHead);
WebHeaderCollection resHead = new WebHeaderCollection();
resHead.Add("Set-Cookie", "SomeCookie");
mock.Setup(client => client.ResponseHeaders).Returns(resHead);
// 実際の呼び出し
LivetubeClient livetube = new LivetubeClient(factory);
Assert.True(livetube.Login("hakusai", "password"));
reqHead.Clear();
resHead.Add("Set-Cookie", "SomeCookie");
Assert.True(livetube.Login("hakusai", "password"));
// 結果の確認
Assert.AreEqual("application/x-www-form-urlencoded", reqHead["Content-Type"]);
byte[] bytes = Encoding.ASCII.GetBytes("user=hakusai&password=password");
mock.Verify(client => client.UploadData("http://livetube.cc/login", "POST", bytes));
mock.Verify(client => client.DownloadString("http://livetube.cc/logoff"));
livetube.Dispose();
}
示例4: LogoffTest
public void LogoffTest()
{
// モックの設定
var factory = new MockWebClientFactory();
var mock = factory.MockClient;
WebHeaderCollection reqHead = new WebHeaderCollection();
mock.Setup(client => client.Headers).Returns(reqHead);
WebHeaderCollection resHead = new WebHeaderCollection();
resHead.Add("Set-Cookie", "SomeCookie");
mock.Setup(client => client.ResponseHeaders).Returns(resHead);
// 実際の呼び出し
LivetubeClient livetube = new LivetubeClient(factory);
Assert.True(livetube.Login("hakusai", "password"));
reqHead.Clear();
resHead.Clear();
livetube.Logoff();
// 結果の確認
Assert.AreEqual("SomeCookie", reqHead["Cookie"]);
mock.Verify(client => client.DownloadString("http://livetube.cc/logoff"));
livetube.Dispose();
}
示例5: MeasureFastReflectionPaths
static long MeasureFastReflectionPaths()
{
const int iterations = 1000000;
long ran = 0;
var sourceMethod = typeof(WebHeaderCollection).GetMethod("AddInternal", BindingFlags.NonPublic | BindingFlags.Instance);
var @delegate = (AddHeaderDelegate) Delegate.CreateDelegate(typeof(AddHeaderDelegate), sourceMethod);
var instanceExpression = Expression.Parameter(typeof(WebHeaderCollection));
var nameParamExpression = Expression.Parameter(typeof(string));
var valueParamExpression = Expression.Parameter(typeof(string));
var methodCallExpression = Expression.Call(instanceExpression, sourceMethod, nameParamExpression, valueParamExpression);
var lambda = Expression.Lambda<AddHeaderDelegate>(methodCallExpression, new[]
{
instanceExpression, nameParamExpression, valueParamExpression
});
var expression = lambda.Compile();
var method = new DynamicMethod(
"",
null,
new[] {typeof(WebHeaderCollection), typeof(string), typeof(string)},
typeof(Program),
true);
var ilGenerator = method.GetILGenerator();
ilGenerator.Emit(OpCodes.Ldarg_0);
ilGenerator.Emit(OpCodes.Ldarg_1);
ilGenerator.Emit(OpCodes.Ldarg_2);
ilGenerator.Emit(OpCodes.Callvirt, sourceMethod);
ilGenerator.Emit(OpCodes.Ret);
var dynamicDelegate = (AddHeaderDelegate) method.CreateDelegate(typeof(AddHeaderDelegate));
var whc = new WebHeaderCollection();
CodeTimer.Time(true, "delegate",
iterations,
() =>
{
@delegate(whc, "test", "abc");
@delegate(whc, "test2", "abc1");
@delegate(whc, "test3", "abc2");
@delegate(whc, "test4", "abc3");
@delegate(whc, "test5", "abc4");
@delegate(whc, "test6", "abc5");
whc.Clear();
});
CodeTimer.Time(true, "expression",
iterations,
() =>
{
expression(whc, "test", "abc");
expression(whc, "test2", "abc1");
expression(whc, "test3", "abc2");
expression(whc, "test4", "abc3");
expression(whc, "test5", "abc4");
expression(whc, "test6", "abc5");
whc.Clear();
});
CodeTimer.Time(true, "delegate",
iterations,
() =>
{
dynamicDelegate(whc, "test", "abc");
dynamicDelegate(whc, "test2", "abc1");
dynamicDelegate(whc, "test3", "abc2");
dynamicDelegate(whc, "test4", "abc3");
dynamicDelegate(whc, "test5", "abc4");
dynamicDelegate(whc, "test6", "abc5");
whc.Clear();
});
return ran;
}