最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - .NET 4.8 HttpClient throws ArgumentException: only http or https schemas allowed - Stack Overflow

programmeradmin2浏览0评论

I am trying to call a web service with HttpClient, same as always:

await client.GetAsync(";);

However, with this particular service I am running into an

ArgumentException: only 'http' and 'https' schemas are allowed.

at System.Net.Http.HttpRequestMessage.set_RequestUri(Uri value)
at System.Net.Http.HttpClientHandler.CreateResponseMessage(HttpWebResponse webResponse, HttpRequestMessage request)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) ...

Looking at the response headers in the browser debugger, the response has the content-location header returned as resource://example/123, which of course is neither http nor https.

This service works fine in every other browser/client I've tried; the .NET 8.0 HttpClient works.

It is only .NET Framework that is unable to handle this.

I tried adding in a custom handler in the HttpClient pipeline, but the exception happens before it reaches my custom handler.

I also tried switching the DefaultRequestHandler to WebRequestHandler to no avail.

Is there a way to intercept the response headers before the HttpResponseMessage gets created?

Or is .NET 4.8 just completely unable to handle non-http responses?

发布评论

评论列表(0)

  1. 暂无评论