使用HttpClient的C#代码如下:
public class TestClass
{
private static readonly HttpClient _httpClient = new HttpClient();
public async Task TestMethod ()
{
//...
_httpClient.BaseAddress = new Uri("http://xxx");
//...
}
}
运行时报错
System.InvalidOperationException: This instance has already started one or more requests. Properties can only be modified before sending the first request.
at System.Net.Http.HttpClient.CheckDisposedOrStarted()
at System.Net.Http.HttpClient.set_BaseAddress(Uri value)
4 回答
慕的地6264312
TA贡献1817条经验 获得超6个赞
我还以为java类库~
不清楚你上下文,但堆栈貌似很明白。
不过还是推荐这种低级类库别用了,直接用RestSharp,我写外挂有时都用这玩意儿,认证、序列化等等封装都比较可以。
- 4 回答
- 0 关注
- 1560 浏览
添加回答
举报
0/150
提交
取消