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
Joy2DWorld
  • Members
  • 562 posts
  • Last active: Jun 30 2014 07:48 PM
  • Joined: 04 Dec 2006
small suggest.

replace
  ; Gather numeric response value
   RetValue := SubStr(RetValue,1,3)

with
regexmatch(retValue,"\b(?<Value>\d\d\d)\b",ret)

Joyce Jamce

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

sRequest := DllCall("WinINet\HttpSendRequestA", "uInt",hRequest,"Str",Headers, "uInt",Strlen(Headers), "Str",POSTData,"uInt",Strlen(POSTData))


using the above line will give you trouble when handling binary data which contain a zero.
the zero will cause AHK to calculate a wrong size, and this might corrupt the POSTdata.

To correct it, u might want to use RtlMoveMemory-DllCall, but you will have to manually calculate your offsets on where to place the Binarydata.

use it as this:
DllCall("RtlMoveMemory","uInt",&postDataBlock+Offset,"uInt",&binaryData,"uInt",binaryDataLength)

This will cause to insert the binary data
To setup the POSTdata Length correctly just use dummy entries as i demonstrated with using the ImageShack Uploader example.

It 1st creates a POSTdata block by using dummy Values (creates with VarSetCapacity(dummy,fileSize,32) - 32 is Ascii-Value of A_Space)

all these values are put together to just big block, its size gets calculated with StrLen (which works here, since we only handle ASCII values)

and after that the RtlMoveMemory inserts the binary data into the block

hope this helps ... btw why dont u just use the function itself instead of ripping out several dll calls?

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

ok so question
this is still a bit deep for me (understanding this well enuff to modify it)
I can use the heck out of it tho except below
but our workplace has a proxy server and i need to use NTLM
http://msdn.microsoft.com/en-us/library/aa383144(VS.85).aspx
im a bit lost when it comes to implementing this into the scripts so far
:( and well i dont seem to have the depth of knowledge to make anything even remotely workable from it

[ Moderator!: MSDN link fixed ]
thanks for the fix
Actually the more in the msdn i read i think i might even be pointed in the wrong direction
basically our proxy uses our Domain login information for the proxy user
In IE we arent prompted but when i use any winhttp function i get blank results
seems like im getting blocked at the proxy for instance

WININET_Init() 
MsgBox % UrlGetContents("https://ahknet.autohotkey.com") 
WININET_UnInit() 
return
fine at home work pc returns blank
and im able to view this site without restriction on work pc in IE

basically my question is this is there a way to send proxy username or pass with this or lerner's version of these functions
Never lose.
WIN or LEARN.

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

basically my question is this is there a way to send proxy username or pass with this or lerner's version of these functions


i researched a bit, and this is what i learned:

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.

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
sweet thanks
ill give it a try and let you know how ti works out
Never lose.
WIN or LEARN.

derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007
this is where i found the information bout the header injection:

http://www.codeguru....hp/t-59121.html

greets
dR

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

DHMH
  • Members
  • 230 posts
  • Last active: Mar 25 2012 10:34 AM
  • Joined: 17 Jul 2008
Hi DerRaphael:
Can you help me?
I want to get the link of a cover from <!-- m -->http://www.cdcovers.cc/<!-- m --> , but I only have the name of the game!
i.e. I want to get the cover of Age Of Empires only with the name!
How?
Thx in advance!
Greets,
DHMH

twhyman
  • Members
  • 348 posts
  • Last active: Sep 17 2014 01:55 AM
  • Joined: 07 Dec 2005
DerRaphael this is amazing, those functions is exactly what i was needed :)

you rock! keep up the good job!

Twhyman
(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination.

  • Guests
  • Last active:
  • Joined: --
I'm confused...the examples all include #include httpQuery.ahk....
But where is this file?? I don't see any links for downloading it??

SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006
You're kidding, right?
Read the first post again (carefully).

[edit]
Well... That was rude... Sorry.
You're not seeing a download link because it's not a download.
It's the 6th block of Code in the first post (clearly labeled httpQuery 0.3.4).

degarb
  • Members
  • 315 posts
  • Last active: May 03 2015 07:35 PM
  • Joined: 14 Feb 2007
I have a ahk that work great, below. But compile it to exe, it fails to run, and tells me that acertain line doesn't contain a recognizable action: DllCall("RtlMoveMemory","uInt",Dest,"uInt",&buffer%A_Index%,"uInt",A_LoopField)
, Dest += A_LoopField


Anyone can figure this out?


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

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

fileappend,..%html%`n,ipstring2.txt
msgbox,, %html%,%html%,10
;end of ipquery
   ExitApp 
    
#include httpQuery.ahk

;end of dynquery


derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007
hi i just checkd ur code and it works fine for me. you do have the latest autohotkey available (1.0.47.05) ? tested with 1.0.48 beta, too. works aswell.


this code was used (httpQuery is in my StandardLib so it gets autoincluded)
#noenv
length := httpQuery(html,"http://checkip.dyndns.org")
varSetCapacity(html,-1)

msgbox,, demo,%html%,10
   ExitApp

greets
dR

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

degarb
  • Members
  • 315 posts
  • Last active: May 03 2015 07:35 PM
  • Joined: 14 Feb 2007
It works for me fine, except when I compile it to exe, which wont run.

Did you compile to exe?

derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007
yes .... by using standard compiler
still working (my firewall asks for permission but that was excepted)

greets
dR

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

degarb
  • Members
  • 315 posts
  • Last active: May 03 2015 07:35 PM
  • Joined: 14 Feb 2007
Verified, a version update needed!

You indeed rock.

BUt I do think a wizzard is needed. Moreover, to clarify, I always do 1,2,3 steps. 1. Why needed and where. 2. Here is my block code to #include in in dir and your ahk at end(or begining) 3. Here are the block of code to edit.

This stuff is rather deep: reaching into wininet, html posts/queries/header, etc. All while some obcessed fool like me, wishes to cut 400k off exe. One half of my brain said, not worth it, the other half was looking at future power of such an ability.

Again, thanks, you and this whole community are so generous. It brings tears to my eyes.

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.) Never mind, keep your energies here.