LoginSignup
7
11

More than 5 years have passed since last update.

PowerShell : Invoke-Webrequestメモ

Last updated at Posted at 2019-01-06

動機

Windows PowerShell上でcurlが正常に動いてくれなかった(文字列のエスケープ処理)ので、代替となるコマンドを探してみた。

コマンド

Invoke-Webrequest
Invoke-WebRequest -Headers @{"Content-type"="application/json"} -Method Post -Body '{"jsonrpc":"2.0","id":1,"method":"eth_accounts","params":[]}' http://localhost:8545

curlを利用する場合、bodyのjsonキーや値を囲む「"」をエスケープすることで解決可能。
(Invoke-Webrequestではエスケープ不要)

curl
curl -H "Content-type: application/json" -X POST -d "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"eth.accounts\",\"params\":[]}" http://localhost:8545

Invoke-Webrequestの結果は以下のとおり。

StatusCode        : 200
StatusDescription : OK
Content           : {"jsonrpc":"2.0","id":1,"result":["0x6a66af57467ca3c9d5c52ea00b582662706974ce","0x70967e3578a254f09
                    ff6ed5fd31cbb3c1a0ec719"]}

RawContent        : HTTP/1.1 200 OK
                    Vary: Origin
                    Content-Length: 126
                    Content-Type: application/json
                    Date: Sun, 06 Jan 2019 03:49:18 GMT

                    {"jsonrpc":"2.0","id":1,"result":["0x6a66af57467ca3c9d5c52ea00b582662706974ce...
Forms             : {}
Headers           : {[Vary, Origin], [Content-Length, 126], [Content-Type, application/json], [Date, Sun, 06 Jan 2019 0
                    3:49:18 GMT]}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : mshtml.HTMLDocumentClass
RawContentLength  : 126
7
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
11