本文整理汇总了C#中HttpRequest.AddArgument方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequest.AddArgument方法的具体用法?C# HttpRequest.AddArgument怎么用?C# HttpRequest.AddArgument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.AddArgument方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Given_argument_name_and_value_are_defined_And_method_is_GET_When_adding_argument_Then_argument_added
public void Given_argument_name_and_value_are_defined_And_method_is_GET_When_adding_argument_Then_argument_added()
{
// setup
var mockHost = "www.test.com";
var mockPath = "/index.html";
var mockUrl = mockHost + mockPath;
var mockArgumentName = "ArgumentName";
var mockArgumentValue = "ArgumentValue";
var assembledRequest = new StringBuilder();
assembledRequest.Append("GET " + mockPath + "?" + mockArgumentName + "=" + mockArgumentValue + " HTTP/1.0\n");
assembledRequest.Append("Host: ");
assembledRequest.Append(mockHost);
assembledRequest.Append("\nConnection: Close");
assembledRequest.Append("\n\n");
var expectedBytes = Encoding.UTF8.GetBytes(assembledRequest.ToString());
var target = new HttpRequest(mockUrl);
// execution
target.AddArgument(mockArgumentName, mockArgumentValue);
// assertion
var result = target.ToByteArray();
Assert.AreEqual(expectedBytes, result, "Argument not added");
}
示例2: StringBuilder
public void Given_nultiple_argument_names_and_values_are_defined_And_method_is_POST_When_adding_argument_Then_all_arguments_added()
{
// setup
var mockHost = "www.test.com";
var mockPath = "/index.html";
var mockUrl = mockHost + mockPath;
var mockArgumentName1 = "ArgumentName";
var mockArgumentValue1 = "ArgumentValue";
var mockArgumentName2 = "SecondArgumentName";
var mockArgumentValue2 = "SecondArgumentValue";
var mockArgumentName3 = "ArgumentNameThree";
var mockArgumentValue3 = "ArgumentValueThree";
var assembledRequest = new StringBuilder();
assembledRequest.Append("POST " + mockPath + " HTTP/1.0\n");
assembledRequest.Append("Host: ");
assembledRequest.Append(mockHost);
assembledRequest.Append("\nConnection: Close");
assembledRequest.Append("\nContent-Type: application/x-www-form-urlencoded");
assembledRequest.Append("\nContent-Length: " + (
mockArgumentName1.Length + mockArgumentValue1.Length + 1 +
mockArgumentName2.Length + mockArgumentValue2.Length + 2 +
mockArgumentName3.Length + mockArgumentValue3.Length + 2).ToString());
assembledRequest.Append("\n\n");
assembledRequest.Append(mockArgumentName1 + "=" + mockArgumentValue1 +
"&" + mockArgumentName2 + "=" + mockArgumentValue2 +
"&" + mockArgumentName3 + "=" + mockArgumentValue3);
var expectedBytes = Encoding.UTF8.GetBytes(assembledRequest.ToString());
var target = new HttpRequest(mockUrl, HttpMethod.POST);
// execution
target.AddArgument(mockArgumentName1, mockArgumentValue1);
target.AddArgument(mockArgumentName2, mockArgumentValue2);
target.AddArgument(mockArgumentName3, mockArgumentValue3);
// assertion
var result = target.ToByteArray();
Assert.AreEqual(expectedBytes, result, "Argument not added");
}
示例3: Given_argument_name_is_not_defined_And_method_is_POST_When_adding_argument_Then_argument_not_added
public void Given_argument_name_is_not_defined_And_method_is_POST_When_adding_argument_Then_argument_not_added()
{
// setup
var mockHost = "www.test.com";
var mockPath = "/index.html";
var mockUrl = mockHost + mockPath;
var assembledRequest = new StringBuilder();
assembledRequest.Append("POST " + mockPath + " HTTP/1.0\n");
assembledRequest.Append("Host: ");
assembledRequest.Append(mockHost);
assembledRequest.Append("\nConnection: Close");
assembledRequest.Append("\nContent-Type: application/x-www-form-urlencoded");
assembledRequest.Append("\nContent-Length: 0");
assembledRequest.Append("\n\n");
var expectedBytes = Encoding.UTF8.GetBytes(assembledRequest.ToString());
var target = new HttpRequest(mockUrl, HttpMethod.POST);
// execution
target.AddArgument("", "");
// assertion
var result = target.ToByteArray();
Assert.AreEqual(expectedBytes, result, "Argument not ignored");
}