2

Using PowerShell 5, I'm downloading from a REST endpoint by doing:

$result = Invoke-RestMethod -Method Get -Uri "http://example.com/endpoint/item"

The result is 4Mb+ in size aprox. And sometimes $result is not a PSObject as I expect, but a string, which contains an incomplete JSON response.

So somehow I suspect there is a timeout, or something going on. But if that is the thing, then i tried using the TimeoutSec parameter with a very large number, like this:

$result = Invoke-RestMethod -Method Get -Uri "http://example.com/endpoint/item" -TimeoutSec 10000

I had no luck: the response is broken (missing part on the JSON string).

Anyway, if there is a timeout involved, should'nt it throw an error?

Also, may be the problem is not on client side, but server side? I'm confused on which side is responsible here.

Javier Castro
  • 321
  • 3
  • 12
  • Possible duplicate of [ConvertFrom-Json max length](http://stackoverflow.com/questions/16854057/convertfrom-json-max-length) – briantist May 04 '16 at 16:44

1 Answers1

1

It appears that you only get a PSObject from Invoke-RestMethod if it is able to convert the JSON string successfully. For a 4MB response this probably won't work. You can check this yourself by passing the the string through ConvertFrom-Json which will likely throw an error.

Similar questions were answered recently here:

In short, you need to create a JavaScriptSerializer and set the MaxJsonLength appropriately.

Community
  • 1
  • 1
Charlie Joynt
  • 4,411
  • 1
  • 24
  • 46