Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Accessing a web page
Message
De
16/04/2013 01:51:22
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
01570924
Message ID:
01571032
Vues:
53
>>>I want to be able to call this link from VFP - how do I do it
>>>
>>>http://www.logixonline.co.uk/intcouriers2/newsite/client_login/index.asp
>>
>>Use the following code as a template, it's a slightly modified version of code I use in my own application. You must change the last URLs.
>>lnTime=12000 && 12 seconds
>>lox=.Null.
>>Release lox
>>Public lox
>>oShell = Createobject("Shell.Application")
>>&& A collection of the open windows that belong to the Shell
>>oShellWindows = oShell.Windows
>>For Each oIE In oShellWindows
>>   If "IEXPLORE.EXE" $ Justfname(Upper(oIE.FullName))
>>      If 'CLIENT LOGIN'$Upper(oIE.LocationName)
>>         lox=oIE
>>         llAlredyup=.T.
>>         Exit
>>      Endif
>>   Endif
>>Endfor
>>oShellWindows = Null
>>oShell = Null
>>If !llAlredyup And Vartype(lox)#'O'
>>   lox=Createobject('internetexplorer.application')
>>   lox.Navigate('http://www.logixonline.co.uk/intcouriers2/newsite/client_login/index.asp')
>>   lox.Visible=.T.
>>   Wait 'Navigating!' Window Nowait
>>   If !NavComplete(lox,lnTime)
>>      ??Chr(7)
>>      Wait 'Timeout feil!' Window
>>      lox.Visible=.F.
>>      Release lox
>>      Return
>>   Endif
>>   Wait Clear
>>Endif
>>lox.Visible=.T.
>>declare integer SetForegroundWindow in win32api Integer
>>SetForegroundWindow(lox.HWND)
>>SetForegroundWindow(_vfp.HWNd)
>>
>>If NavComplete(lox,lnTime)
>>   lox.Document.All.mainFrame.contentWindow.Document.Forms.login.username.Value='Username'
>>   lox.Document.All.mainFrame.contentWindow.Document.Forms.login.passwort.Value="password"
>>   lox.document.all.mainFrame.contentWindow.document.forms.login.submit.click()
>>   If !NavComplete(lox,lnTime)
>>      ??Chr(7)
>>      Wait 'timeout error!' Window
>>      lox.Visible=.F.
>>      Release lox
>>      Return
>>   Endif
>>endif
>>
>>Function NavComplete
>>   Lpara toIE, tnTimeout
>>   lnTimeout=Iif( Type("tnTimeout")="N",tnTimeout ,60 )
>>   lnTimeElapsed=0
>>   lnStartSeconds=Seconds()
>>   Do While .T.
>>      If toIE.ReadyState=4 And !toIE.Busy
>>         Do While .T.
>>            If toIE.Document.ReadyState="complete"
>>               Return .T.
>>            Endif
>>            If (Seconds()-lnStartSeconds)>lnTimeout
>>               Return .F.
>>            Endif
>>         Enddo
>>      Endif
>>      If (Seconds()-lnStartSeconds)>lnTimeout
>>         Return .F.
>>      Endif
>>   Enddo
>
>Thanks Tore - I have another solution but I will try yours

With my solution you will also be able to have the Client ID filled in, and the submit button clicked. I modified my earlier code slightly, to match the actual URL:
Local oShell As [Shell.Application]
Local lcClientID, llAlredyup, lnTime, oIE, oShellWindows

m.lcClientID = [something]

m.lnTime = 12000 && 12 seconds
m.lox = .Null.
Release m.lox
Public lox
m.oShell = Createobject([Shell.Application])
&& A collection of the open windows that belong to the Shell
oShellWindows = m.oShell.Windows
m.llAlredyup = .F.
For Each oIE In oShellWindows
   If [IEXPLORE.EXE] $ Justfname(Upper(oIE.FullName))
      If [CLIENT LOGIN] $ Upper(oIE.LocationName)
         m.lox = oIE
         m.llAlredyup = .T.
         Exit
      Endif
   Endif
Endfor
oShellWindows = Null
m.oShell = Null
If !m.llAlredyup And Vartype(m.lox) # [O]
   m.lox = Createobject([internetexplorer.application])
   m.lox.Navigate([http://www.logixonline.co.uk/intcouriers2/newsite/client_login/index.asp])
   m.lox.Visible = .T.
   Wait [Navigating!] Window Nowait
   If !NavComplete(m.lox, m.lnTime)
      ??Chr(7)
      Wait [Timeout feil!] Window
      m.lox.Visible = .F.
      Release m.lox
      Return
   Endif
   Wait Clear
Endif
m.lox.Visible = .T.
Declare Integer SetForegroundWindow In win32api Integer
SetForegroundWindow(m.lox.HWnd)
SetForegroundWindow(_vfp.HWnd)
If NavComplete(m.lox, m.lnTime)
   m.lox.Document.Forms.loginform.Password.innertext = m.lcClientID
   m.lox.Document.Forms.loginform.submit.Click()

   If !NavComplete(m.lox, m.lnTime)
      ??Chr(7)
      Wait [timeout error!] Window
      m.lox.Visible = .F.
      Release m.lox
      Return
   Endif
Endif

Function NavComplete
   Lpara toIE, tnTimeout
   lnTimeout = Iif( Type([tnTimeout]) = [N], tnTimeout, 60 )
   lnTimeElapsed = 0
   lnStartSeconds = Seconds()
   Do While .T.
      If toIE.ReadyState = 4 And !toIE.Busy
         Do While .T.
            If toIE.Document.ReadyState = [complete]
               Return .T.
            Endif
            If (Seconds() - lnStartSeconds) > lnTimeout
               Return .F.
            Endif
         Enddo
      Endif
      If (Seconds() - lnStartSeconds) > lnTimeout
         Return .F.
      Endif
   Enddo
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform