考虑以下代码,其中BaseAddress定义了部分URI路径。
using (var handler = new HttpClientHandler())
using (var client = new HttpClient(handler))
{
client.BaseAddress = new Uri("http://something.com/api");
var response = await client.GetAsync("/resource/7");
}
我希望这能向发出GET请求http://something.com/api/resource/7。但事实并非如此。
经过一些搜索,我找到了这个问题和答案:HttpClient与BaseAddress。建议将其放置/在末尾BaseAddress。
using (var handler = new HttpClientHandler())
using (var client = new HttpClient(handler))
{
client.BaseAddress = new Uri("http://something.com/api/");
var response = await client.GetAsync("/resource/7");
}
它仍然不起作用。这里是文档:HttpClient.BaseAddress这是怎么回事?
饮歌长啸