Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过GetAsync()将参数传递给_C#_Unit Testing_Asp.net Core_Asp.net Core Mvc - Fatal编程技术网

C# 通过GetAsync()将参数传递给

C# 通过GetAsync()将参数传递给,c#,unit-testing,asp.net-core,asp.net-core-mvc,C#,Unit Testing,Asp.net Core,Asp.net Core Mvc,我有一个要测试的API。这是一个方法的签名 [HttpGet("{param}")] public async Task<IActionResult> Get(string param, string param2) { ... } param是路由的一部分,但如何使param2进入该方法 将param2作为查询字符串传递给服务器。客户端代码: HttpClient client = new HttpClient(); string uri = "http://localhost

我有一个要测试的API。这是一个方法的签名

[HttpGet("{param}")]
 public async Task<IActionResult> Get(string param, string param2)
{
...
}

param是路由的一部分,但如何使param2进入该方法

param2
作为查询字符串传递给服务器。客户端代码:

HttpClient client = new HttpClient();
string uri = "http://localhost:63779/api/controller_name/param/?param2=SOME_VALUE";
HttpResponseMessage response = await client.GetAsync(uri);

使用查询字符串它是一个get
?param=foo¶m2=bar
添加,我们可以使用字符串插值,例如:HttpClient=new HttpClient();字符串param2=“someValue”;字符串uri=$“{param2}”;HttpResponseMessage response=wait client.GetAsync(uri);裁判:
HttpClient client = new HttpClient();
string uri = "http://localhost:63779/api/controller_name/param/?param2=SOME_VALUE";
HttpResponseMessage response = await client.GetAsync(uri);