最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin8PV0评论

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?

Post a comment

comment list (0)

  1. No comments so far