小编Max*_*son的帖子

如何在 C# 中将查询字符串添加到 HttpClient.BaseAdress 中?

我试图将查询字符串传递到 BaseAddress 但它无法识别引号“?”。

引用破坏了 URI

首先我创建我的 BaseAddress

httpClient.BaseAddress = new Uri($"https://api.openweathermap.org/data/2.5/weather?appid={Key}/"); 
Run Code Online (Sandbox Code Playgroud)

然后我调用 GetAsync 方法,尝试添加另一个参数

using (var response = await ApiHelper.httpClient.GetAsync("&q=mexico"))....
Run Code Online (Sandbox Code Playgroud)

这是代码调用的 URI

https://api.openweathermap.org/data/2.5/&q=mexico
Run Code Online (Sandbox Code Playgroud)

c# httpclient

4
推荐指数
1
解决办法
5824
查看次数

标签 统计

c# ×1

httpclient ×1