1
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VBScriptでcURL

Last updated at Posted at 2019-08-24

VBScriptでcURLを行うには、WinHttp.WinHttpRequestオブジェクトを使用します。

GET

curl_get.vbs
Dim http: Set http = CreateObject("WinHttp.WinHttpRequest.5.1")

Dim petId: petId = 1
Dim url: url = "https://petstore.swagger.io/v2/pet/" & petId

With http
	.Open "GET", url, False
	.Send
	Wscript.Echo .Status & " " & .StatusText
	Wscript.Echo .ResponseText
End With
>cscript /nologo curl_get.vbs
200 OK
{"id":1,"category":{"id":0,"name":"DOGS"},"name":"doggie","photoUrls":["string"],"tags":[{"id":0,"name":"string"}],"status":"available"}

POST

curl_post.vbs
Dim http: Set http = CreateObject("WinHttp.WinHttpRequest.5.1")

Dim url: url = "https://petstore.swagger.io/v2/store/order"

Dim data: data = "{ ""id"": 1, ""petId"": 1, ""quantity"": 0, ""shipDate"": ""2019-08-24T04:07:54.083Z"", ""status"": ""placed"", ""complete"": false}"

With http
	.Open "POST", url, False
	.SetRequestHeader "Content-Type", "application/json"
	.Send data
	Wscript.Echo .Status & " " & .StatusText
	Wscript.Echo .ResponseText
End With
>cscript /nologo curl_post.vbs
200 OK
{"id":1,"petId":1,"quantity":0,"shipDate":"2019-08-24T04:07:54.083+0000","status":"placed","complete":false}

WinHttpRequestオブジェクトの詳細なリファレンスはコチラ

1
4
1

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
1
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?