; exmpl.imageshack.httpQuery.ahk
; This example uploads an image and constructs a multipart/form-data Type
; for fileuploading and returns the XML which is returned to show the stored Imagepath
FileSelectFile,image
FileGetSize,size,%image%
SplitPath,image,OFN
FileRead,img,%image%
VarSetCapacity(placeholder,size,32)
boundary := makeProperBoundary()
post:="--" boundary "`ncontent-disposition: form-data; name=""MAX_FILE_SIZE""`n`n"
. "1048576`n--" boundary "`ncontent-disposition: form-data; name=""xml""`n`nyes`n--"
. boundary "`ncontent-disposition: form-data; name=""fileupload""; filename="""
. ofn """`nContent-type: " MimeType(img) "`nContent-Transfer-Encoding: binary`n`n"
. placeholder "`n--" boundary "--"
headers:="Content-type: multipart/form-data, boundary=" boundary "`nContent-Length: " strlen(post)
DllCall("RtlMoveMemory","uInt",(offset:=&post+strlen(post)-strlen(Boundary)-size-5)
,"uInt",&img,"uInt",size)
size := httpQuery(result:="","http://www.imageshack.us/index.php",post,headers)
VarSetCapacity(result,-1)
Gui,Add,Edit,w800 h600, % result
Gui,Show
return
GuiClose:
GuiEscape:
ExitApp
makeProperBoundary(){
Loop,26
n .= chr(64+a_index)
n .= "0123456789"
Loop,% StrLen(A_Now) {
Random,rnd,1,% StrLen(n)
Random,UL,0,1
b .= RegExReplace(SubStr(n,rnd,1),".$","$" (round(UL)? "U":"L") "0")
}
Return b
}
MimeType(ByRef Binary) {
MimeTypes:="424d image/bmp|4749463 image/gif|ffd8ffe image/jpeg|89504e4 image/png|4657530"
. " application/x-shockwave-flash|49492a0 image/tiff"
@:="0123456789abcdef"
Loop,8
hex .= substr(@,(*(a:=&Binary-1+a_index)>>4)+1,1) substr(@,((*a)&15)+1,1)
Loop,Parse,MimeTypes,|
if ((substr(hex,1,strlen(n:=RegExReplace(A_Loopfield,"\s.*"))))=n)
Mime := RegExReplace(A_LoopField,".*?\s")
Return (Mime!="") ? Mime : "application/octet-stream"
}
#include httpQuery.ahk |