How to parse JSON from the Invoke-WebRequest in PowerShell? -


when sending request server, uses self-signed certificate:

add-type @"     using system.net;     using system.security.cryptography.x509certificates;     public class trustallcertspolicy : icertificatepolicy {         public bool checkvalidationresult(             servicepoint srvpoint, x509certificate certificate,             webrequest request, int certificateproblem) {             return true;         }     } "@ [system.net.servicepointmanager]::certificatepolicy = new-object trustallcertspolicy $response=invoke-webrequest -uri https://yadayada:8080/bla -method echo $response 

i'm getting following response:

statuscode        : 200 statusdescription : ok content           : {123, 10, 108, 111...} rawcontent        : http/1.1 200 ok                     content-length: 21                     date: sat, 11 jun 2016 10:11:03 gmt                      {                         flag:false                     } headers           : {[content-length, 21], [date, sat, 11 jun 2016 10:11:03 gmt]} rawcontentlength  : 21 

content contains wired numbers, went after rawcontent, how parse json inside, ignoring headers? or there clean way content numbers?

you replace invoke-webrequest invoke-restmethod auto-converts json response psobject can use:

$response = invoke-restmethod -uri "https://yadayada:8080/bla" $response.flag  

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -