gpt4 book ai didi

c# - 通过 GetAsync() 传递参数

转载 作者:行者123 更新时间:2023-12-05 01:41:47 28 4
gpt4 key购买 nike

我有一个要测试的 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 获取到该方法?

最佳答案

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

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

关于c# - 通过 GetAsync() 传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53598582/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com