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

admin2025-04-26  5

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?

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745602369a309383.html

最新回复(0)