我有一个要测试的API。这是一种方法的签名...
[HttpGet("{param}")]
public async Task<IActionResult> Get(string param, string param2)
{
...
}
在测试项目中,我以这种方式构造调用...
HttpClient client = new HttpClient();
string uri = "http://localhost:63779/api/controller_name/param/";
HttpResponseMessage response = await client.GetAsync(uri);
param是路由的一部分,但是如何获取方法的param2?
答案 0 :(得分:2)
将param2
作为查询字符串传递给服务器。客户端代码:
HttpClient client = new HttpClient();
string uri = "http://localhost:63779/api/controller_name/param/?param2=SOME_VALUE";
HttpResponseMessage response = await client.GetAsync(uri);