Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 521 Vote(s) - 3.46 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to parse JSON from the Invoke-WebRequest in PowerShell?

#1
When sending the GET request to the server, which 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

[To see links please register here]

-Method GET
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 some wired numbers, so I went after RawContent, how would I parse the JSON inside, ignoring headers? or is there a clean way to get Content from those numbers?
Reply

#2
You could replace `Invoke-WebRequest` with `Invoke-RestMethod` which auto-converts json response to a `psobject` so you can use:

$response = Invoke-RestMethod -Uri "https://yadayada:8080/bla"
$response.flag
Reply

#3
If you have a need to use `Invoke-WebRequest` over `Invoke-RestMethod` you can convert it to an object by turning it into a string first

$response = Invoke-WebRequest -Uri "https://yadayada:8080/bla"
$jsonObj = ConvertFrom-Json $([String]::new($response.Content))
Reply

#4
This way:

$response = Invoke-WebRequest -Uri <your_uri>
if ($response.statuscode -eq '200') {
$keyValue= ConvertFrom-Json $response.Content | Select-Object -expand "<your_key_name>"
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through