I have killed 3 hours today and don\'t understand why?
I have easy script:
$user = \'icm\'
$pass = \'icm\'
$pair = \"$($user):$($pass)\"
$url = \'http://
I had also the same problem with RabbitMQ, the cause is the escaping of %2f
in URL.
See Percent-encoded slash (“/”) is decoded before the request dispatch
With the tricks of the above answer, it works both in ISE and console :
$urlFixSrc = @"
using System;
using System.Reflection;
public static class URLFix
{
public static void ForceCanonicalPathAndQuery(Uri uri)
{
string paq = uri.PathAndQuery;
FieldInfo flagsFieldInfo = typeof(Uri).GetField("m_Flags", BindingFlags.Instance | BindingFlags.NonPublic);
ulong flags = (ulong) flagsFieldInfo.GetValue(uri);
flags &= ~((ulong) 0x30);
flagsFieldInfo.SetValue(uri, flags);
}
}
"@
Add-Type -TypeDefinition $urlFixSrc -Language CSharp
$url = [URI]$url
Invoke-WebRequest -Uri $url -Headers $headers -ContentType "application/json"