Passing parameters to via GetAsync()
10,351
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);
Related videos on Youtube
Author by
John
Updated on June 04, 2022Comments
-
John almost 2 years
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?
-
Sean T over 5 yearsuse query string it it's a get
?param=foo¶m2=bar
-
-
Refu about 3 yearsAdding, We could use string interpolation, ex: HttpClient client = new HttpClient(); string param2 = "someValue"; string uri = $"localhost:63779/api/controller_name/param/?param2={param2 }"; HttpResponseMessage response = await client.GetAsync(uri); ref:docs.microsoft.com/en-us/dotnet/csharp/language-reference/…