Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[function] httpQuery GET and POST requests - update 0.3.6


  • Please log in to reply
94 replies to this topic

Poll: Should a more generic function be released which will include the already available web functions, such as header queries, uri encoding, base encoding, etc ? (144 member(s) have cast votes)

Should a more generic function be released which will include the already available web functions, such as header queries, uri encoding, base encoding, etc ?

  1. yes, i'd like to have one function to get all neccessary http functionalities in one instead of collecting each for my own (160 votes [96.39%])

    Percentage of vote: 96.39%

  2. no, i prefer collecting the functions i need (5 votes [3.01%])

    Percentage of vote: 3.01%

  3. neither nor ... explained in post (1 votes [0.60%])

    Percentage of vote: 0.60%

Vote Guests cannot vote
derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007

Now, anyone found a similar trick to telnet? ( have an email check and cddb scrip that relies on controlsend to a telnet that takes me half second to hide, and sometimes I don't think the send works so well.)


solved

take a look here: [function] send/expect() for Autohotkey TelnetAlike sessions

greets
dR

degarb
  • Members
  • 309 posts
  • Last active: Jun 01 2014 03:39 PM
  • Joined: 14 Feb 2007
By the way, any wput replacement natively?

Need help, I am coming on another glitch. I have a simple ahk that works, using your code, but embedded in a larger ahk-a dyndnsupdateclient-, the html variable (the html telling me that the ip was updated or not) is returning blank. Is this because variable used previously on another case, in the ahk?

dynquery:
;replace wget
#noenv 
html     := "" 
URL      := "http://me:mypassword@members.dyndns.org/nic/update?" 
POSTData := "hostname=hyhost.homeip.net&myip=173.89.183.11" 

length := httpQuery(html,URL,POSTdata) 
varSetCapacity(html,-1) 

fileappend,..%html%`n,log.txt
msgbox,, %html%,%html%,1
;end of dynquery
filedelete,dyndnserrorlog.txt
sleep, 1000
fileappend, %html%,dyndnserrorlog.txt
IfInString, html, bad, msgbox, Your ini has errors!
IfInString, html, nochg, msgbox,,Warning!,May be updating too often!,1

   ExitApp 
    
#include httpQuery.ahk

This is working fine. But in the huge file, the html variable is returning blank. Listing other variables looks like working fine.

;this code is the main ahk to dyndns.com updating client, only missing help and httpquery.ahk
;todo reinstall  jump.htm homehost.html 
;done:eliminate wget with http://www.autohotkey.com/forum/viewtopic.php?p=235283#235283
;done:http://www.autohotkey.com/forum/viewtopic.php?t=33506
;


;FileInstall, wget\wget.exe, wget\wget.exe
FileInstall, helpme.txt, helpme.txt
FileInstall, source-code.ahk, source-code.ahk
FileInstall, httpQuery.ahk, httpQuery.ahk

#singleinstance
DetectHiddenWindows, On
settitlematchmode,2

iniread,hostname, dyn.ini,Prefs,hostname

trays:
Menu, Tray, Tip, Dyna-Dingle! Another Dyndns.com updater 4 free! %hostname%
menu:
menu, tray, Nostandard
;Menu, Tray, Click, 1
;menu, tray, add,Dial/Hang,dialhang
;menu, tr5y, Default,Dial/Hang


menu, tray, add,Check and update dyndns.com, firstcheck

Menu, MySubmenu, add, List_Recent_Executed_Code
Menu, MySubmenu, add, List_Variables
Menu, MySubmenu, add, Update-Log_View
Menu, tray, add, Tools,:MySubmenu

;menu, tray, add,ListLines,ListLines
;menu, tray, add,ListVars,ListVars
;menu, tray, add,View Update Logs,Logview
menu, tray, add,Help and Configure,help
Menu, tray, add  ; Creates a separator line.
menu, tray, add,Pause, Pause
menu, tray, add,Exit , exit



firstcheck:
fileread, String3, ip.txt
StringReplace, String4, String3, `n, 
StringReplace, String5, String4, %a_space%, 
StringReplace, oldip, String5,
, 


;sleep 360000
FileDelete, ipstring.txt 
;;;run wget\wget -O ipstring.txt "http://checkip.dyndns.org" ,,hide
ipquery1:
;replaces wget
#noenv 
html     := "" 
URL      := "http://checkip.dyndns.org" 
POSTData := "" 

length := httpQuery(html,URL,POSTdata) 
varSetCapacity(html,-1) 

fileappend,%html%,ipstring.txt
;msgbox,, %html%,ip is %html%,10
;end of ipquery


sleep, 3000
FileRead, String, ipstring.txt
StringReplace, String2, String, <html><head><title>Current IP Check</title></head><body>Current IP Address: , 
StringReplace, String3, String2, </body></html>, 
StringReplace, String4, String3, `n, 
StringReplace, String5, String4, %a_space%,
StringReplace, String5a, String5, |, 
 StringReplace, currentip, String5a,
, 

;msgbox,  %currentip% = %oldip%
ifequal, currentip, %oldip%,	goto, sleeping


inicheck:
ifnotexist,%A_WorkingDir%\dyn.ini
{
	iniwrite,me, dyn.ini,Prefs,UserName
	iniwrite,hostname.homeip.net, dyn.ini,Prefs,hostname
	iniwrite,password, dyn.ini,Prefs,Password
		runwait, notepad.exe dyn.ini
		runwait, notepad.exe helpme.txt

}


	iniread,username, dyn.ini,Prefs,UserName
	iniread,hostname, dyn.ini,Prefs,hostname
	iniread,password, dyn.ini,Prefs,Password


sleep, 1800
; increase above value to 180000 so running at startup works on all machines

run, %A_WinDir%\system32\ipconfig.exe >> d:\ipnow.txt


dnyservice:
FileDelete, ipstring.txt 
;;;run wget\wget -O ipstring.txt "http://checkip.dyndns.org" ,,hide
ipquery2:
;replaces wget
#noenv 
html     := "" 
URL      := "http://checkip.dyndns.org" 
POSTData := "" 

length := httpQuery(html,URL,POSTdata) 
varSetCapacity(html,-1) 

fileappend,%html%,ipstring.txt
;msgbox,, %html%,%html%,10
;end of ipquery

sleep, 3000
FileRead, String, ipstring.txt

StringReplace, String2, String, <html><head><title>Current IP Check</title></head><body>Current IP Address: , 
StringReplace, String3, String2, </body></html>, 
StringReplace, String4, String3, `n, 
StringReplace, String5, String4, %a_space%, 
StringReplace, String5a, String5, |, 
StringReplace, currentip, String5a,
, 

goto, writejumppage

ipconfig:
controlsend,, ipconfig > d:\ip4now.txt{enter}, ahk_id %ControlHwnd%
sleep, 2500
controlsend,, exit{enter}, ahk_id %ControlHwnd%
FileRead, String3, d:\ip4now.txt
StringReplace, String4, String3, `n, 
StringReplace, String5, String4, %a_space%,
StringReplace, String5a, String5, |,  
StringReplace, currentip, String5a,
, 
 
FileDelete, d:\ip4now.txt 
StringMid, currentip, currentip, 460,14 

writejumppage:
msgbox, ,Updating ip!,Updating ip %currentip%! (writejumpage),1
;3 lines below is test code to see in sendkeys working on second cmd.
FileDelete, homehost.htm
fileappend,  <HEAD> `n<meta HTTP-EQUIV="REFRESH" content="0; url=http://%currentip%">`n </HEAD>,homehost.htm
sleep, 2500


;;;runwait wget\wget.exe -O wget\dyndnsupdate.txt "http://%username%:%password%@members.dyndns.org/nic/update?hostname=%hostname%&myip=%currentip%{enter}",%a_working_Dir%/wget,hide
dynquery:
;replace wget
#noenv 
html =
html     := "" 
URL      := "http://%username%:%password%@members.dyndns.org/nic/update?" 
POSTData := "hostname=%hostname%&myip=%currentip%" 

;length := httpQuery(html,URL,POSTdata) 
;varSetCapacity(html,-1) 

fileappend,..%html%`n,log.txt
sleep, 1000
msgbox,, %html%,%html%`nhttp://%username%:%password%@members.dyndns.org/nic/update?hostname=%hostname%&myip=%currentip% ,11
;end of dynquery
filedelete,dyndnserrorlog.txt
sleep, 1000
fileappend, %html%,dyndnserrorlog.txt
IfInString, html, bad, msgbox, Your ini has errors!
IfInString, html, nochg, msgbox,,Warning!,May be updating too often!,1

sleep, 4500
log:
fileappend, New ip is %currentip% Found at %A_MM%-%A_DD% %A_Hour%:%A_Min%..`n, log.txt
;:UrlDownloadToFile, http://%username%:%password%@members.dyndns.org/nic/update?hostname=%hostname%&myip=%currentip%, Filename.txt 
;:run, http://%username%:%password%@members.dyndns.org/nic/update?hostname=%hostname%&myip=%currentip%

;MsgBox, Your IP is: %currentip%
filedelete, ip.txt
;msgbox, ,writeing ip,%currentip%,3
fileappend, %currentip%, ip.txt
fileread, String3, ip.txt
StringReplace, String4, String3, `n, 
StringReplace, String5, String4, %a_space%, 
StringReplace, String5a, String5, |, 
StringReplace, oldip, String5a,
, 

sleeping:
;msgbox,, Sleeping!, Sleeping!,1 
sleep 720000
FileDelete, ipstring.txt 
;;;run wget\wget -O ipstring.txt "http://checkip.dyndns.org" ,,hide


ipquery3:
;replaces wget
#noenv 
html     := "" 
URL      := "http://checkip.dyndns.org" 
POSTData := "" 

length := httpQuery(html,URL,POSTdata) 
varSetCapacity(html,-1) 

fileappend,%html%,ipstring.txt
;msgbox,, %html%,%html%,10
;end of ipquery

sleep, 3000
FileRead, String, ipstring.txt
StringReplace, String2, String, <html><head><title>Current IP Check</title></head><body>Current IP Address: , 
StringReplace, String3, String2, </body></html>, 
StringReplace, String4, String3, `n, 
StringReplace, String5, String4, %a_space%, 
StringReplace, String5a, String5, |, 
StringReplace, currentip, String5a,
, 
fileread, String3, ip.txt
StringReplace, String4, String3, `n, 
StringReplace, String5, String4, %a_space%, 
StringReplace, String5a, String5, |, 
StringReplace, oldip, String5a,
, 

ifnotequal, currentip, %oldip%,msgbox, ,Updating ip!,Updating ip!,3
ifnotequal, currentip, %oldip%, goto, writejumppage
goto, sleeping

exit:
exitapp

List_Recent_Executed_Code:
ListLines
goto, sleeping
Return

List_Variables:
ListVars
goto, sleeping
Return


help:
		runwait, notepad.exe dyn.ini
		runwait, notepad.exe helpme.txt
goto, sleeping
Return

Update-Log_View:
		runwait, notepad.exe log.txt
goto, sleeping
Return

Pause:
pause
return

#include httpQuery.ahk


derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007
i can only make a wild guess, but to me it look like the problem is in this line:

URL      := "http://%username%:%password%@members.dyndns.org/nic/update?"
POSTData := "hostname=%hostname%&myip=%currentip%"

the questionmark at the end of the url indicates that rest of params should be appended as get params in the query. instead u r passing the params via post (which is a different way)

also the percentsign within the quotationmarks wont work.

u have top rewrite that part to something like:

url := "http://" username ":" password "@members.dyndns.org/nic/update?"
     . "hostname=" hostname "&myip= "currentip

postdata is only needed when having a form whose content is transferred using the post method.

greets
dR

degarb
  • Members
  • 309 posts
  • Last active: Jun 01 2014 03:39 PM
  • Joined: 14 Feb 2007
That solves it.

I don't understand why the little ahk works with same line, but not the large one (with bad line).

Thanks.

Joy2DWorld
  • Members
  • 562 posts
  • Last active: Jun 30 2014 07:48 PM
  • Joined: 04 Dec 2006

That solves it.

I don't understand why the little ahk works with same line, but not the large one (with bad line).

Thanks.


i helpful,

there is "=" and ":="

with = you don't use quotes,

eg. this = This is GREAT!



but how to use vars ?

put them in %here%.

ie. with = the answer is %answer%


but := works different. you need quotes.

this := "something is here"

vars are naked

this := "the answer is " answer

so,

this := "the %answe%r"

gives you

the %answer%.

and not... the actual answer.


hope helps

geeneeyes
  • Members
  • 66 posts
  • Last active: Jan 26 2012 01:02 PM
  • Joined: 24 May 2006
<!-- w -->www.autohotkey.com/forum/viewtopic.php?p=246328<!-- w -->

twhyman
  • Members
  • 348 posts
  • Last active: Jun 08 2013 09:10 PM
  • Joined: 07 Dec 2005
Hi,

Is it possible to use HTTPQuery to handle cookies?

I am asking this because i am creating a movie poster grabber from a site that requires cookies to be saved, if you dont have cookies you get blocked. :)

I just love beeing able to do POST :).

Awaiting your reply,
Twhyman

soccer18soccer18
  • Members
  • 101 posts
  • Last active: Sep 12 2009 10:51 PM
  • Joined: 18 Nov 2008
ok i am VERY confused with this. ive read the first post about 5 times and been looking at everything for like half an hour. so can someone PLEASE help me out a bit?

i have a few questions about how to get this to work:

1) Do i have to install anything to get this to work?
2) How do I get it to do this: Post a search term on Google, then search for it and get the list of results?



Any help is apreciated, greatly apreciated.


Thanks.

geeneeyes
  • Members
  • 66 posts
  • Last active: Jan 26 2012 01:02 PM
  • Joined: 24 May 2006

1) Do i have to install anything to get this to work?
2) How do I get it to do this: Post a search term on Google, then search for it and get the list of results?

You have to download and save this script in the same folder as your script.
Also put this code in your script
#Include httpQuery.ahk


soccer18soccer18
  • Members
  • 101 posts
  • Last active: Sep 12 2009 10:51 PM
  • Joined: 18 Nov 2008
what do i download and save?

post a link please.

Thanks so much!

hobdiddy
  • Guests
  • Last active:
  • Joined: --
hi i was trying to get your sample imageshack script working for another site http://decaptcher.com/client/

here's my mod...
#SingleInstance,Force
#Include httpquery.ahk

DUser := ""
DPass := ""

FileSelectFile,image
   FileGetSize,size,%image%
   SplitPath,image,OFN
   FileRead,img,%image%
   VarSetCapacity(placeholder,size,32)
   boundary := makeProperBoundary()

Post:="--" boundary "`ncontent-disposition: form-data; name=""function""`n`npicture2`n--"
	. boundary "`ncontent-disposition: form-data; name=""username""`n`n" DUser "`n--"
	. boundary "`ncontent-disposition: form-data; name=""password""`n`n" DPass "`n--"
	. boundary "`ncontent-disposition: form-data; name=""pict""; filename="""
	. ofn """`nContent-type: " MimeType(img) "`n`n" placeholder "`n--"
	. boundary "`ncontent-disposition: form-data; name=""pict_to""`n`n 0`n--"
	. boundary "`ncontent-disposition: form-data; name=""pict_type""`n`n0`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://decaptcher.com/poster/",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"
}

no matter what i try, though i may not understand enough yet, it always returns nothing.

here's some documentation from there site.

Example 4. POST a picture

method="post"
action="http://decaptcher.com/poster/"
enctype="multipart/form-data">











Example 5. Claim picture as badly recognized

method="post"
action="http://decaptcher.com/poster/"
enctype="multipart/form-data">









POST API returns a line of text separated with | character

Example 6. POST API returned string

0|107|44685|0|0|n7hjks


Format of the string is the following:

ResultCode|MajorID|MinorID|Type|Timeout|Text


if anyone could provide some assistance that would be appriciated.

thx again for httpquery!

fures
  • Members
  • 88 posts
  • Last active: May 25 2013 11:04 PM
  • Joined: 31 Jan 2008
Anybody knows how to get the redirected url (the page the redirect landed on) from httpQuery?

thanks
fures

donv
  • Members
  • 24 posts
  • Last active: Mar 27 2013 11:02 PM
  • Joined: 18 Oct 2008
Could anyone give me a quick example syntax of how to use httpQuery against a server using HTTPS instead of http.

i read the docs, and read the code and i dont get it.

I tried this and results come back empty.

REPORTURL = "https://www.amazon.com"
length := httpQuery(htmlx,REPORTURL,POSTdata)
varSetCapacity(htmlx,-1)

another question would be, is httpQuery the best way to do this, or is there another method which is better?

thank you in advance!
-don

Voltron43
  • Members
  • 76 posts
  • Last active: May 06 2011 07:48 PM
  • Joined: 27 Mar 2009

You need to inject a header into the datastream which looks like this:

header := "Proxy-Authorization: Basic " base64(username":"password)

Keep in mind that Basic Authetification is case sensitive.

username:password needs to be base64 encoded.


I am behind a proxy at work as well, and I'm trying to understand how to get Example III to work while being behind the proxy.

What's the proper way to base64 encode the username and password?

How do I properly inject the header using Example III?

I'm a total noob when it comes to ahk.

Thanks in advance.

Precise
  • Members
  • 31 posts
  • Last active: May 23 2011 01:55 AM
  • Joined: 30 Dec 2007
I'm used to the functionality and freedom of cURL but I will give this a shot. Not having to include an external application will be nice for small projects. Secure connections with the ssl version of curl require several files. I'm just hoping that I don't run into something I need that this has not covered yet. Thanks a lot Raphael.