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
96 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 ? (158 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 (174 votes [96.67%])

    Percentage of vote: 96.67%

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

    Percentage of vote: 2.78%

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

    Percentage of vote: 0.56%

Vote Guests cannot vote
heresy
  • Members
  • 291 posts
  • Last active: Sep 26 2008 10:47 PM
  • Joined: 11 Mar 2008
@ skrommel

the weird thing is they returns 404 even it's POSTed successfully. when i removed error handling for 404 temporarily in HttpQuery. i could got the result properly.

just simply add 404 at the line around 183 in httpquery.ahk

if !(InStr("100 200 201 202 302",RetValue)) {
should be

if !(InStr("100 200 201 202 302 404",RetValue)) {
httpQuery(Var, "http://pastebin.com/pastebin.php", "poster=HttpQueryTest&format=Python&paste=send&expiry=d&code2=Testing a bit..")
VarSetCapacity(Var, -1)
Gui, Add, Edit, w600 h400 , %Var%
RegExMatch(Var,"<li class=""highlight""><a href=""(.+?)"">",Out)
Gui, Add, Edit, w600, %Out1%
Gui, Show

Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com

derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007
@heresy this patch is not needed i fixed it in the function thus resulting an update to v0.3.3. disabling the 404 handling is IMHO not a good idea.

The Problem as far as i've understood it, was that the httpQuery function tried to access the Header response Location setting which is not accessible at that time (so its a timing problem) introducing the httpQueryDwFlags variable solves this problem (also others such as pages from mozdev) an example how to set this property and use it properly is shown in 1st post as example V.

more updates:
httpQueryReferer [sic] allows custom referrer set
httpQueryAcceptTypes allows custom set accept types for received datastreams.

greets
DerRaphael

All scripts, unless otherwise noted, are hereby released under CC-BY

skrommel
  • Members
  • 193 posts
  • Last active: Jun 07 2010 08:30 AM
  • Joined: 30 Jul 2004
:) Then it wasn't just me... Thanks a million, DerRaphael!

Skrommel

heresy
  • Members
  • 291 posts
  • Last active: Sep 26 2008 10:47 PM
  • Joined: 11 Mar 2008

@heresy this patch is not needed i fixed it in the function thus resulting an update to v0.3.3. disabling the 404 handling is IMHO not a good idea.

dude i never expect that you can solve it without breaking the easy interface :) well done!
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com

AnAHKUser
  • Guests
  • Last active:
  • Joined: --
Great work DerRaphael, really inspiring :D

y did hob
  • Guests
  • Last active:
  • Joined: --
i am currently having a problem understanding why i cannot get an updated page source when i use this script. i am sure i am missing something but honestly i am still a beginner.

#Include httpQuery-0-3-2.ahk
s:
	html =
	URL = http://watchout4snakes.com/creativitytools/RandomWord/RandomWord.aspx

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

	StringGetPos,HPos1,html,"randomWord"
	HPos1 += 13
	StringGetPos,HPos2,html,<,,%HPos1%
	Count := HPos2 - HPos1
	HPos1 += 1
	StringMid,word,html,%HPos1%,%Count%

	msgbox,%word%
	sleep,5000
	goto,s

my second query is if this is the correct way to set global var for httpquery. this part i am totally unsure. would these need to be set before the include?

global httpProxy := 193.146.209.5:80
global httpQueryReferer := "http://www.autohotkey.com"


Azerty
  • Members
  • 72 posts
  • Last active: Jan 16 2009 10:08 AM
  • Joined: 19 Dec 2006
Hi

My suggestions :

1) By default, have an auto-proxy discovery, ie. enable a keyword for global var httpProxy (for instance "auto-discover", have that httpProxy var default to that keyword. This can be achieved by the following way, for instance : read "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" value "ProxyServer"
This would enable running other's submitted httpQuery-based scripts without change (my first tries on your samples won't work due to my Proxomitron usage)

2) add a comment in your code refering to this topic (always useful not to have to remember or add to favorites a topic for each useful script :) )

3) don't put a version number in the suggested filename for the lib in 1st post, since the published code shouldn't rely on it in #include. To explain further, I made a copy/paste of lib in file "httpQuery-0-3-3.ahk" (as suggested in first post), then copied the xkdc comics sample to a "sample_http.ahk" file in same dir, ran it and... it of course broke since that's an implicit include under "httpQuery.ahk" name... I think as a generic good rule of thumb that lib file names should not include version number, but, of course, the version number must be kept inside the file itself.

You may look at the header of my Ascii85 code for sample of what I mean.

Anyway, very nice and impressive work. Thanks for sharing. Will probably become very popular.
Assembler-coded MCode.ahk ASCII85.ahk library

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007

...(my first tries on your samples won't work due to my Proxomitron usage)...

Sorry can't resist to say Hi to a fellow Proxomitron user. I've been using it for a very long time.

ahklerner
  • Members
  • 1386 posts
  • Last active: Oct 08 2014 10:29 AM
  • Joined: 26 Jun 2006

HttpRetCodes...418=I'm a teapot (RFC 2324)...

no way..

RFC 2324
2.3.2 418 I'm a teapot

Any attempt to brew coffee with a teapot should result in the error
code "418 I'm a teapot". The resulting entity body MAY be short and
stout.

huh.
Posted Image
ʞɔпɟ əɥʇ ʇɐɥʍ

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
fascinating stuff really
Never lose.
WIN or LEARN.

derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007
minor bugfix in version 0.3.4 - sometimes the returned size may differ from updated size via VarSetCapacity(data,-1). The returned size was correct, but the datasize might have had some corrupted data which lead to some strange chars being appended to the variable. this is fixed, as httpQuery sets buffersize greater than needed and prefills the variable with binary zeros.

also fixed the examples just to include httpQuery.ahk not the httpQuery-varVersion.ahk name style.

thanks
and have fun
dR

All scripts, unless otherwise noted, are hereby released under CC-BY

hobdiddy
  • Guests
  • Last active:
  • Joined: --
I may be missing something but how would we handle the data that shows up in the "Query String" tab on HttpFox?

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

I may be missing something but how would we handle the data that shows up in the "Query String" tab on HttpFox?


the data showing up in the query string is the url for httpQuery function.
When clicking on the POST tab and there on the RAW view u'll get a ready to copy POST entry which was actually sent to the target server.
by modifying the data you see there (u'll need to uriEncode your fresh ones) you can use this to send it via autohotkey to the server with a modified content.

greets
dR

All scripts, unless otherwise noted, are hereby released under CC-BY

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
I am not really sure which thread is the correct one for help so here goes <!-- m -->http://www.autohotke... ... 244#219244<!-- m --> i know these 2 threads are related so if someone knows the answer let me know
Never lose.
WIN or LEARN.

Lixx9000
  • Guests
  • Last active:
  • Joined: --
Can't seem to get it to work right. :evil:

087: if (Strlen(POSTDATA)>0)  
087: {
088: HTTPVerb := POST
089: if StrLen(Headers)=0  
090: HEADERS := Content-Type: application/x-www-form-urlencoded
091: }
096: hRequest := DllCall("WinINet\HttpOpenRequestA","uInt",hConnect,"Str",HTTPVerb,"Str",lpszUrlPath . lpszExtrainfo,"Str",ProVer := "HTTP/1.1", "Str",httpQueryReferer,"Str",httpQueryAcceptTypes,"u
103: sRequest := DllCall("WinINet\HttpSendRequestA", "uInt",hRequest,"Str",Headers, "uInt",Strlen(Headers), "Str",POSTData,"uInt",Strlen(POSTData))
107: VarSetCapacity(header, 2048, 0)  
108: VarSetCapacity(header_len, 4, 0)  
112: Loop,5
113: if ((headerRequest:=DllCall("WinINet\HttpQueryInfoA","uint",hRequest,"uint",21,"uint",&header,"uint",&header_len,"uint",0))=1)  
113: if ((headerRequest:=DllCall("WinINet\HttpQueryInfoA","uint",hRequest,"uint",21,"uint",&header,"uint",&header_len,"uint",0))=1)  
113: if ((headerRequest:=DllCall("WinINet\HttpQueryInfoA","uint",hRequest,"uint",21,"uint",&header,"uint",&header_len,"uint",0))=1)  
113: if ((headerRequest:=DllCall("WinINet\HttpQueryInfoA","uint",hRequest,"uint",21,"uint",&header,"uint",&header_len,"uint",0))=1)  
113: if ((headerRequest:=DllCall("WinINet\HttpQueryInfoA","uint",hRequest,"uint",21,"uint",&header,"uint",&header_len,"uint",0))=1)  
117: if (headerRequest=1)  
125: res := timeout
128: Loop,Parse,res,
,

129: {
130: RetValue := A_LoopField
131: Break
135: if (RetValue="timeout")  
135: {
136: html := Error: timeout
137: Return,-1
014: varSetCapacity(html,-1)  
016: Gui,Add,Edit,w600 +Wrap r25,html
017: Gui,Show