[H2] oh() - 对象化 http 包装

许多实用脚本和封装函数, 可以让您编写脚本更加便捷高效
arcticir
Posts: 473
Joined: 17 Nov 2013, 11:32

[H2] oh() - 对象化 http 包装

23 Aug 2016, 01:18

基础示例:

Code: [Select all] [Download] GeSHi © Codebox Plus

#Include <ObjTree>
f:={option:option:=[],head:head:=[]}
f.url:="http://www.bing.com/search?qs=bs&&first=50form=QBLH&q=AutoHotkey"
f.type:="get"
f.Agent:="Mozilla/5.0 (Linux; Android 6.1.1; Nexus 7 Build/JRO03S) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/48.0.1025.166 Safari/535.19"
f.end:="ObjTree"
option[6]:=70000
head["Content-Type"]:="application/x-www-form-urlencoded"
oh(f)
MsgBox,Test


输出:
    time - 耗时
    heads - Headers
    list - 对象化 Headers 项 (f.list.Etag)
    size - 数据大小
    err - 错误信息
    txet - 网页数据
    bin - 下载二进制数据到变量
    hash - MD2/MD4/MD5/SHA1/SHA256/SHA384/SHA512, If in
    json - json-Object
    decode
    affix - 附加信息
      gzip-size - Original size
      charset


输入:
    url
    name - Naming
    head - 参数对象
    option - 参数对象
    type - 请求方案 (get,post,head...)
    pug - 进度回调函数
    end - 完成回调函数
    decide - 获取标头后,指定函数判断是否继续执行
    gh - (true) 获取 Headers ; OR type:="head"
    agent - user-agent settings
    file - 文件路径
    fileName - 自动获取文件名.无法时将使用它的值作为默认名称. 需要在"file"指定目录.
    fileExt - 同上
    bin - (true) (f.bin)
    decode - (true) Web 解码 (f.decode)
    json - (true) 将 Web 数据转换为对象 (f.json)
    hash - hash类型
    Verify - (true) 强制验证大小
    proxy
    charset
    referer


Image





=============




oh()

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus





附:

    自动请求 gzip
    自动识别 charset
Last edited by arcticir on 23 Aug 2016, 22:34, edited 8 times in total.
arcticir
Posts: 473
Joined: 17 Nov 2013, 11:32

Re: [H2] oh() - Object-oriented packaging http

23 Aug 2016, 06:31

Example:


下载页面到变量

Code: [Select all] [Download] GeSHi © Codebox Plus

MsgBox % oh("http://www.bing.com/search?qs=bs&&first=50form=QBLH&q=AutoHotkey")
; or:
f:=oh({url:"http://www.bing.com/search?qs=bs&&first=50form=QBLH&q=AutoHotkey",result:1})
MsgBox % f.text



获取 API JSON 并转换为对象

Code: [Select all] [Download] GeSHi © Codebox Plus

f:=[]
f.url:="https://query.yahooapis.com/v1/public/yql?q=select`%20*`%20from`%20html`%20where`%20url`%3D'http`%3A`%2F`%2Fen.wikipedia.org`%2Fwiki`%2FYahoo'`%20and`%20xpath`%3D'`%2F`%2Ftable`%2F*`%5Bcontains(.`%2C`%22Founder`%22)`%5D`%2F`%2Fa'&format=json&env=store`%3A`%2F`%2Fdatatables.org`%2Falltableswithkeys"
f.json:=1
oh(f)
MsgBox % ObjTree(f.json)



下载图片并上传到 google 搜索

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus




下载 ahk.exe, 并验证是否需要升级

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus




获取 http headers

Code: [Select all] [Download] GeSHi © Codebox Plus

f:={option:o:=[]}
f.url:="http://dwz.cn/3ZUOAQ"
f.type:="head" ;or f.gh:=1
o[63]:=0x00000002 ;Set Prohibit redirects option
oh(f)
MsgBox % "Location:`n" f.list.Location "`n`nAll headers:`n" f.heads



下载 Vivaldi 并显示进度
Image

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus




上传图片到 Photobucket

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Return to “脚本函数”

Who is online

Users browsing this forum: No registered users and 1 guest