AutoHotkey Community

It is currently May 27th, 2012, 6:59 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Auto login to a webpage
PostPosted: February 10th, 2012, 5:53 pm 
Offline

Joined: March 19th, 2007, 12:43 am
Posts: 532
I need to use WinHttpRequest to accomplish this task? Can someone explain or point me ahk example of how?
For instance how do I login to this page: http://www.fmpilot.com/Express/ServiceDesk.asp
?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2012, 6:49 pm 
Offline

Joined: July 20th, 2009, 6:01 am
Posts: 166
Location: Amsterdam
This is perhaps not what you want to hear, but I recommend using the browser extension Last Pass for auto-log-ins: it is specialized for this task and will always perform better than AHK. Unless you need to integrate this into your program or something.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2012, 7:09 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5482
Location: the tunnel(?=light)
I don't know how Last Pass would necessarily perform better than AHK unless you're taking about using it on a non-IE browser. Here's a solution using the latest version (AHK_L) when using Internet Explorer and that page is open and is the active page:

Code:
pwb :=   IE_Get()
pwb.document.all["txtUserid"].value :=   << your username here >>
pwb.document.all["txtPassword"].value :=   << your password here >>
pwb.execScript["javascript:document.frmServiceDesk.submit();"]

IE_Get(hWnd="") {

   static   IID :=   "{332C4427-26CB-11D0-B483-00C04FD90119}"

   if   !hWnd
      ControlGet, hWnd, hWnd, , Internet Explorer_Server1, ahk_class IEFrame
   return   ComObj(9,ComObjQuery(Acc_ObjectFromWindow(hwnd),IID,IID),1)
}

Acc_Init() {
   Static   h
   If   !h
      h :=   DllCall("LoadLibrary","Str","oleacc","Ptr")
}

Acc_ObjectFromWindow(hWnd, idObject = -4) {
   Acc_Init()
   If   DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject&=0xFFFFFFFF, "Ptr", -VarSetCapacity(IID,16)+NumPut(idObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81,NumPut(idObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0,IID,"Int64"),"Int64"), "Ptr*", pacc)=0
      Return   ComObjEnwrap(9,pacc)
}

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2012, 7:21 pm 
Offline

Joined: July 20th, 2009, 6:01 am
Posts: 166
Location: Amsterdam
I'm sure AHK can do it very well technically. But Last Pass does it all automatically and can still get the forms if the page changes (normally it can, at least). I was also assuming the OP wasn't using IE. And it is extremely convenient, because you won't need to do anything, just click the Save Password button that pops up (or whatever it's called). Whenever you go to the log-in page afterwards, you don't even need click "log in": all is done automatically.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2012, 4:20 am 
Offline

Joined: March 19th, 2007, 12:43 am
Posts: 532
Thanks, however I'm looking for a way to update information and download files remotely. I think cURL does something like that if i'm not mistaken.
After some digging I found out how to use GET method, to retrieve raw html of a page

Code:
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("GET", "http://www.google.com")
WebRequest.Send()

Gui, Add, Edit, x12 y10 w710 h320 , % WebRequest.ResponseText()
Gui, Show, w735 h350, html page

ObjRelease(WebRequest)
return

GuiClose:
ExitApp


What I can't find is a decent explanation/examples of how POST should be used. Can anyone try to help me understand this?
Thanks :oops:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2012, 4:33 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
@sinkfaze - the return from ComObjEnwrap needs to take ownership of the pointer so that you're not leaking com objects:
Code:
Return   ComObjEnwrap(9,pacc,1)

Also, to be extremely picky, the IE_Get function is returning a window object, not a webbrowser object.

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2012, 5:02 am 
neXt wrote:
What I can't find is a decent explanation/examples of how POST should be used. Can anyone try to help me understand this?
It might help to search the web with the keywords, WinHttp.WinHttpRequest Post.

For example, I found some relevant topics. The COM syntax is almost the same so you wouldn't have a problem translating them.
Code:
// Instantiate a WinHttpRequest object.
var WinHttpReq = new ActiveXObject("WinHttp.WinHttpRequest.5.1");

// Initialize an HTTP request. 
WinHttpReq.Open("PUT", "http://postserver/newdoc.htm", false);

// Post data to the HTTP server.
WinHttpReq.Send("Post data");


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2012, 5:52 am 
Offline

Joined: March 19th, 2007, 12:43 am
Posts: 532
Thanks, that cleared some things up for me :D
So I'm trying to login to gmail, here's the code that I have so far:
Code:
URL = https://accounts.google.com/ServiceLoginAuth
login := "Email=" . user . "&Passwd=" . pass
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("POST", URL, false)
WebRequest.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")

WebRequest.Send(login)

Gui, Add, Edit, x12 y10 w710 h320 , % WebRequest.ResponseText()
Gui, Show, w735 h350, html page

ObjRelease(WebRequest)
return

GuiClose:
ExitApp


it returns the same login page html when I run it, only this time my username is in the username field. What am I doing wrong here, why isn't it accepting my password?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2012, 9:08 am 
Offline

Joined: March 19th, 2007, 12:43 am
Posts: 532
Here's my latest attempt:
Code:
URL := "https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/ca/&ss=1&scc=1&ltmpl=default&ltmplcache=2"
login := "Email=" . user . "&Passwd=" . pass
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("POST", URL, false)
WebRequest.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")

WebRequest.Send(login)

URL := "https://mail.google.com/mail/ca/?shva=1#inbox"
WebRequest.Open("GET", URL)
WebRequest.Send()

Gui, Add, Edit, x12 y10 w710 h320 , % WebRequest.ResponseText()
Gui, Show, w735 h350, html page

ObjRelease(WebRequest)
return

GuiClose:
ExitApp


It's not working :(


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2012, 11:58 pm 
Offline

Joined: March 19th, 2007, 12:43 am
Posts: 532
Bump. :roll:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 12th, 2012, 9:19 pm 
Offline

Joined: March 19th, 2007, 12:43 am
Posts: 532
Anyone? :(


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: migz99, sjc1000 and 73 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group