AutoIt WinHttpは絶対入れたほうがいいUDF

autoit winhttp AutoIT

WebDriver UDFでもお馴染みのWinHttp UDFです。これを使えば基本なんでもできると思います。内部ではwinHttp.dllが使われていて、winhttp.dllの winhttp.hに関数は準拠しているっぽいです。なので、winhttp.dll 使い方 とかでググったのを結構参考に出来ると思います。

スポンサーリンク

1. WinHTTP UDFをダウンロード

2019年12月時点での最新版は1.6.4.1です。下記githubページでダウンロードできます。
ダウンロードしたらAutoIt インストールフォルダ\Includes\に入れておきましょう。
#include <WinHttp.au3> と追加してあとはガシガシ書くだけですね。

Releases · dragana-r/autoit-winhttp
Automatically exported from code.google.com/p/autoit-winhttp - dragana-r/autoit-winhttp

2. AutoIt WinHttp フォーラムを見てサンプルなども確認

フォーラムに行きましょう。使い方はとりあえず最初のサンプルコードをコピペし動かせばいいと思います。

WinHTTP functions
The other day mikeytown2 posted one post in HTTP UDF's thread that got me thinking if there is better (different) method to send requests through the HTTP proto...
#include "WinHttp.au3"
Opt("MustDeclareVars", 1)

; Open needed handles
Local $hOpen = _WinHttpOpen()
Local $hConnect = _WinHttpConnect($hOpen, "msdn.microsoft.com")
; Specify the reguest:
Local $hRequest = _WinHttpOpenRequest($hConnect, Default, "en-us/library/aa384101(VS.85).aspx")

; Send request
_WinHttpSendRequest($hRequest)

; Wait for the response
_WinHttpReceiveResponse($hRequest)

Local $sHeader = _WinHttpQueryHeaders($hRequest) ; ...get full header

; Clean
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

; Display retrieved header
MsgBox(0, "Header", $sHeader)

3. エンコーディングはgzipのみらしいdeflateは未対応

フォーラムのどこかに書いてあった記憶があるのですが、deflateは未対応なはずです。
なので、SendRequest時に追加するヘッダに”Accept-Encoding: deflate”は止めたほうがいいです。
ちなみにgzipには対応しているので、通信量大幅減の為にもContent-Encoding: gzip, Accept-Encoding: gzipは入れておいたほうがいいと思います。

I believe that the data served by the server is compressed by deflate inside a zlib stream (RFC1951 + RFC1950), and WinHttp probably works with only former. When you find server that delivers raw deflate (RFC1951) this can be confirmed.

下記フォーラム46ページ中段くらいに書いてありますが、deflateはRFC1951のdeflateのみ対応のようで。(と言いつつ自分は詳しくないので使うの止めています)

WinHTTP functions

4. 参考になりそうなスクリプトが書いてあるフォーラム

autoit winhttp **(探したいキーワード)で検索すると大抵同じことで迷っている人が質問していたりします。

4.1 curl -> WinHttp

Convert curl command to WinHttp
Hi All i am currently trying to add a function to my project that can send SMS, i have gone with Twilio for the sms service that use a REST API. I have never wo...

4.2 ログインしてファイルダウンロード

これならWebDriver UDF + Chrome使ってもいいんじゃないかと。Users/(username)/Downloads/にダウンロードされたら、ダウンロードボタン押した以降にあるファイルがダウンロードしたファイルと見なす的にすれば。

winhttp - download an exe file
Hi guys.I'am using this UDF for http operations.I already make an auto-login script for a website which is required to download an exe file which is only avail...

4.3 WinHttp UDFフォーラムのページ

WinHTTP functions
The other day mikeytown2 posted one post in HTTP UDF's thread that got me thinking if there is better (different) method to send requests through the HTTP proto...

コメント

タイトルとURLをコピーしました