I am using System.Net.HttpClient in a client application and needing to PUT to a third party service I have no control over. The third party service gives responses such as:
Date: Wed, 04 Jun 2025 20:38:32 GMT
Server: Apache
X-LL-Request-Id: aECuyNDHz8BcYDvfmg9JCgAAATk
Content-Type: application/llsd+xml
Content-Length: 65859
Content-Location: slcap://InventoryAPIv3/category/1854a12a-d07f-bb17-a00c-82b739b05698/links
Location: slcap://InventoryAPIv3/category/1854a12a-d07f-bb17-a00c-82b739b05698/links
Vary: Accept,Accept-Encoding,X-Untrusted-Path,X-Untrusted-Query
Access-Control-Allow-Origin: *
Note the Location and Content-Location fields have an slcap:// protocol. These fields are also not important for my purposes at this time.
However, when I call HttpClient.PutAsync(uri, content, ct) the response I get throws an exception:
System.ArgumentException
HResult=0x80070057
Message=Only 'http' and 'https' schemes are allowed.
Parameter name: value
Source=System.Net.Http
StackTrace:
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)
This is due to HttpRequestMethod copying the response Location into a new request:
request.RequestUri = webResponse.ResponseUri
Which validates the RequestUri:
if (value != null && value.IsAbsoluteUri && !HttpUtilities.IsHttpUri(value))
{
throw new ArgumentException(SR.net_http_client_http_baseaddress_required, "value");
My question is what is the best way to mitigate this in .NET Framework? It only seems to happen on PUT requests.
LocationURI, a custom schema is perfectly within spec. It's simply .NET Framework over-validating it.