Powershellでcurl - 2023/8/6
Powershellでもデフォルトでcurlコマンドを利用できるが、以下エラーが出る場合がある。
郵便番号検索API( http://zipcloud.ibsnet.co.jp/doc/api )での例。
code:powershell
PS > curl https://zipcloud.ibsnet.co.jp/api/search?zipcode=7830060
curl : Internet Explorer エンジンを使用できないか、Internet Explorer の初回起動構成が完了していないため、応
答のコンテンツを解析できません。UseBasicParsing
パラメーターを指定して再試行してください。
発生場所 行:1 文字:1
+ curl https://zipcloud.ibsnet.co.jp/api/search?zipcode=7830060
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotImplemented: (:) Invoke-WebRequest, NotSupportedException
+ FullyQualifiedErrorId : WebCmdletIEDomNotSupportedException,Microsoft.PowerShell.Commands.InvokeWebR
equestCommand
裏でIE使ってるんですか?という感じだが、今後IEを立ち上げることは無いだろうということで回避したい。
これは、-UseBasicParsin オプションを付けると回避できる。
code:powershell
PS miton > curl https://zipcloud.ibsnet.co.jp/api/search?zipcode=7830060 -UseBasicParsing
StatusCode : 200
StatusDescription : OK
Content : {
"message": null,
"results": [
{
"address1": "高知県",
"address2": "南国市",
"address3": "蛍が丘",
"kana1": "コウチケン",
"kana2": "ナンコクシ",
"kana3": "ホタルガオカ",
"prefcode": "39",
"zipcod...
RawContent : HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
X-Cloud-Trace-Context: 49f3e95f887c9f0250f1ec10d42ae201
Content-Length: 290
Content-Type: text/plain;charset=utf-8
Date: Sun, 06 Aug 2023 07:39:25 G...
Forms :
Headers : {Access-Control-Allow-Origin, *, [X-Cloud-Trace-Context, 49f3e95f887c9f0250f1ec10d42a
e201], Content-Length, 290, Content-Type, text/plain;charset=utf-8...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml :
RawContentLength : 290
参考
https://www.vwnet.jp/windows/PowerShell/2018082101/AvoidIEError.htm
https://news.mynavi.jp/article/win10tips-492/
#powershell
#windows
#curl