2

I've noticed a strange behavior with Invoke-RestMethod, where the last period of the -Uri parameter is truncated.

For example:

Invoke-RestMethod -Method Get -Uri http://example.com/this.

Looking at Fiddler, the request goes to http://example.com/this where the last period is removed.

What is puzzling is that this behavior is only present when running the method on PowerShell, but not on PowerShell ISE. Both PowerShell and PowerShell ISE are using the same engine version.

 Major  Minor  Build  Revision
 -----  -----  -----  --------
 5      1      16299  547     

Someone mentioned this phenomenon here, but it was never answered. I tried to encode the string using UriBuilder but the issue is still present. What could be happening here??

MrKrabwell
  • 21
  • 2
  • What happens if you encode the final period into `%2E` – Theo Aug 02 '18 at 19:17
  • I also found a workaround [here](https://stackoverflow.com/questions/6191412/url-encode-periods/38800236#38800236) to end the url in a slash. Don't know if that works for you too.. – Theo Aug 02 '18 at 19:27
  • 1
    `%2E` or using a trailing `/` did not solve the problem. It seems like a problem only running PowerShell. – MrKrabwell Aug 03 '18 at 20:27
  • Does it take out multiple period characters or just the last one? I mean: What if you add an extra dot to the url in case it ends with a period? – Theo Aug 03 '18 at 21:10
  • Did you try quoting the url? – Theo Aug 03 '18 at 21:12
  • 1
    It only takes out the period if the path ends in a period, e.g. "/this.path." becomes "/this.path". I also noticed that it will remove all periods if it ends in multiple periods, e.g. "/this.path....." will become "/this.path". Quoting the URL did not fix the problem either. – MrKrabwell Aug 06 '18 at 19:57
  • Well.. no easy fix then. I did find a workaround [here](https://stackoverflow.com/questions/856885/httpwebrequest-to-url-with-dot-at-the-end#2285321) but i haven't tested it. – Theo Aug 06 '18 at 20:32
  • Thanks for all the suggestions. I'll post back here if I find anything useful. – MrKrabwell Aug 07 '18 at 16:09

0 Answers0