Hey All,
I’ve been experimenting with invoke-restmethod. I think I’ve mostly got the hang of it, so I decided that a fun challenge would be to grab the web reputation of a given IP from senderbase. Unfortunately, Senderbase requires you to accept a ToS before you can query the site. I know I can pass the cookie generated by accepting the ToS between sessions, and that’s where I’m running into trouble. I found this solution using .net, but there’s gotta be a way to use cookies with the REST cmdlet, right? I suspect I just have to formulate the header correctly, but I can’t find any useful info on how to do it. Here’s what I have at the moment:
[string]$BaseUri = "https://www.senderbase.org/lookup/?search_string=8.8.8.8" [string]$ContentType = "application/json" $cookie=new-object system.net.cookie $cookie.name = "TOS_accepted" $cookie.path = "/" $cookie.value = "1330588800" $cookie.domain = "www.senderbase.org" $cookie.expires = "01/10/2026 09:15 AM" $Headers=@{ "domain" = $cookie.domain "Path" = $cookie.path "name" = $cookie.name "value" = $cookie.value "expires" = $cookie.expires } $JSONResponse = Invoke-RestMethod -URI $BaseURI -Headers $Headers -ContentType $ContentType -Method Get If($JSONResponse) { Return $JSONResponse } Else { Return $False }
This is my first real foray into the world of web APIs, so any suggestions are welcome.
submitted by /u/laserpewpewAK
[link] [comments]
The post Using cookies with Invoke-RestMethod appeared first on How to Code .NET.