xamarin.forms httpclient 在运行时多次更改 BaseAddress
xamarin.forms httpclient change BaseAddress multiple times runtime
我已将 Xamarin.Forms 更新到最新版本 (4.5.0.530)。
之后我无法更改我的 httpclient 的 BaseAddress。
我有以下代码:
private static HttpClient client = new HttpClient(new NativeMessageHandler());
client = new HttpClient(new NativeMessageHandler());
client.BaseAddress = new Uri(App.hostserveradress);
client.Timeout = TimeSpan.FromMinutes(5);
稍后,在我调用 Web 服务后:
responseReset = await client.PostAsync("GetResetFotos", contentReset);
我想将 BaseAddress 更改为另一个:
client.BaseAddress = new Uri(App.serveradress);
但是当我设置新的 BaseAddress 时出现以下错误:
This instance has already started one or more requests. Properties can only be modified before sending the first request.
在更新之前Xamarin.Forms一切正常,现在我得到了命名错误。
我能做什么?
谢谢。
You don't NEED to set a base address. If you simply use full URLs, you
can make requests to as many sites as you want.
这解决了我的问题,感谢@PaulVrugt
我已将 Xamarin.Forms 更新到最新版本 (4.5.0.530)。 之后我无法更改我的 httpclient 的 BaseAddress。 我有以下代码:
private static HttpClient client = new HttpClient(new NativeMessageHandler());
client = new HttpClient(new NativeMessageHandler());
client.BaseAddress = new Uri(App.hostserveradress);
client.Timeout = TimeSpan.FromMinutes(5);
稍后,在我调用 Web 服务后:
responseReset = await client.PostAsync("GetResetFotos", contentReset);
我想将 BaseAddress 更改为另一个:
client.BaseAddress = new Uri(App.serveradress);
但是当我设置新的 BaseAddress 时出现以下错误:
This instance has already started one or more requests. Properties can only be modified before sending the first request.
在更新之前Xamarin.Forms一切正常,现在我得到了命名错误。
我能做什么?
谢谢。
You don't NEED to set a base address. If you simply use full URLs, you can make requests to as many sites as you want.
这解决了我的问题,感谢@PaulVrugt