简体   繁体   中英

Passing parameters to via GetAsync()

I have an API that I want to test. This is the signature of one method...

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

In the test project I structure the call this way...

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

param is part of the route but how do I get param2 to the method?

Pass param2 as query string ti the server. The client code:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM