PowerShellで、curlコマンドを使用する方法を解説します。
はじめに・実行環境
WindowsのPowershellで、curlコマンドを実行する方法を説明します。
実行環境は以下となります。
- OS:Windows11
- PowerShellのバージョン:5.1.22621.2506
curlコマンドでの接続先は、FastAPI・Uvicornで構築したAPIサーバとします。
curlコマンドを実行する
ここでは、curlコマンドを実行する方法を説明します。
以下が、curlコマンドの実行例です。
PS C:\Workspace> curl "http://192.168.66.14:8000/"
StatusCode : 200
StatusDescription : OK
Content : {"text":"Sample Message\n"}
RawContent : HTTP/1.1 200 OK
Content-Length: 27
Content-Type: application/json
Date: Thu, 25 Jan 2024 10:33:54 GMT
Server: uvicorn
{"text":"Sample Message\n"}
Forms : {}
Headers : {[Content-Length, 27], [Content-Type, application/json], [Date, Thu, 25 Jan 2024 10:33:54 GMT], [Se
rver, uvicorn]}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : System.__ComObject
RawContentLength : 27
curl.exeを実行する
Windows10以降では、PowerShell標準のcurlコマンドの他、Windowsとして提供されている「curl.exe」があります。
ここでは、PowerShellから、curl.exeを実行する方法を説明します。
以下が、curl.exeの実行例です。
curl.exeを普通に実行すると、curlコマンドでの「Content」が取得されるようです。
PS C:\Workspace> curl.exe "http://192.168.66.14:8000/"
{"text":"Sample Message\n"}
今回はシンプルにGETメソッドでデータを取得しただけですが、今後はPOSTメソッドの実行や各種項目を取得する方法を書いていこうと思います。
リンク






コメント