Skip to content

Instantly share code, notes, and snippets.

@tmplinshi
Created March 14, 2016 18:51
Show Gist options
  • Save tmplinshi/1e9b01f02104e5883703 to your computer and use it in GitHub Desktop.
Save tmplinshi/1e9b01f02104e5883703 to your computer and use it in GitHub Desktop.
class http {
static o := ComObjCreate("WinHttp.WinHttpRequest.5.1")
get(args*) {
return this._request("GET", args*)
}
post(args*) {
return this._request("POST", args*)
}
clearCookie() {
this.o := ComObjCreate("WinHttp.WinHttpRequest.5.1")
}
_request(method, url, postData="", obj_headers="") {
this.o.Open(method, url, true)
this._setHeaders(obj_headers, method)
this.o.Send(postData)
this.o.WaitForResponse()
return this.o.ResponseText
}
_setHeaders(obj, method) {
for k, v in obj {
this.o.SetRequestHeader(k, v)
}
if (method = "POST") && !obj["Content-Type"] {
this.o.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment