AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[function] httpQuery GET and POST requests - update 0.3.4
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  

Should a more generic function be released which will include the already available web functions, such as header queries, uri encoding, base encoding, etc ?
yes, i'd like to have one function to get all neccessary http functionalities in one instead of collecting each for my own
95%
 95%  [ 23 ]
no, i prefer collecting the functions i need
0%
 0%  [ 0 ]
neither nor ... explained in post
4%
 4%  [ 1 ]
Total Votes : 24

Author Message
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Sun Jul 27, 2008 11:30 am    Post subject: Reply with quote

@ 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)) {


Code:
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
Back to top
View user's profile Send private message
DerRaphael



Joined: 23 Nov 2007
Posts: 604
Location: 127.0.0.1

PostPosted: Sun Jul 27, 2008 12:00 pm    Post subject: Reply with quote

@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
_________________
Back to top
View user's profile Send private message
skrommel



Joined: 30 Jul 2004
Posts: 181

PostPosted: Sun Jul 27, 2008 11:59 pm    Post subject: Reply with quote

Smile Then it wasn't just me... Thanks a million, DerRaphael!

Skrommel
_________________
www.1HourSoftware.com
Back to top
View user's profile Send private message Visit poster's website
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Mon Jul 28, 2008 9:03 am    Post subject: Reply with quote

DerRaphael wrote:
@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 Smile well done!
_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com
Back to top
View user's profile Send private message
AnAHKUser
Guest





PostPosted: Wed Jul 30, 2008 7:02 am    Post subject: Reply with quote

Great work DerRaphael, really inspiring Very Happy
Back to top
y did hob
Guest





PostPosted: Thu Jul 31, 2008 6:38 pm    Post subject: Reply with quote

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.

Code:
#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?

Code:
global httpProxy := 193.146.209.5:80
global httpQueryReferer := "http://www.autohotkey.com"
Back to top
Azerty



Joined: 19 Dec 2006
Posts: 72
Location: France

PostPosted: Fri Aug 01, 2008 8:54 am    Post subject: Reply with quote

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 Smile )

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
Back to top
View user's profile Send private message
HugoV



Joined: 27 May 2007
Posts: 650

PostPosted: Fri Aug 01, 2008 10:47 am    Post subject: Reply with quote

Azerty wrote:
...(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.
Back to top
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1249
Location: USA

PostPosted: Thu Aug 21, 2008 2:05 am    Post subject: Reply with quote

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

no way..
Quote:
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.
_________________

ʞɔпɟ əɥʇ ʇɐɥʍ
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 1033

PostPosted: Thu Aug 21, 2008 8:43 pm    Post subject: Reply with quote

fascinating stuff really
_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
DerRaphael



Joined: 23 Nov 2007
Posts: 604
Location: 127.0.0.1

PostPosted: Sun Sep 07, 2008 10:52 pm    Post subject: Reply with quote

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
_________________
Back to top
View user's profile Send private message
hobdiddy
Guest





PostPosted: Tue Sep 09, 2008 2:51 am    Post subject: Reply with quote

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



Joined: 23 Nov 2007
Posts: 604
Location: 127.0.0.1

PostPosted: Tue Sep 09, 2008 7:22 pm    Post subject: Reply with quote

hobdiddy wrote:
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
_________________
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 1033

PostPosted: Tue Sep 09, 2008 11:30 pm    Post subject: Reply with quote

I am not really sure which thread is the correct one for help so here goes http://www.autohotkey.com/forum/viewtopic.php?p=219244#219244 i know these 2 threads are related so if someone knows the answer let me know
_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
Lixx9000
Guest





PostPosted: Mon Sep 22, 2008 8:37 am    Post subject: Reply with quote

Can't seem to get it to work right. Evil or Very Mad

Code:
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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4  Next
Page 3 of 4

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group