Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need code to send POST reuest to retrieve URL

Status
Not open for further replies.

dwalker

Technical User
Nov 29, 2002
34
0
0
Hi all

Not exactly an Access VBA question but as everything I do is in Access and you guys are all so helpful...

I need some assistance writing code to retrieve the HTML from a URL that requires a POST method. I can easily retrieve data from URLs that use the GET method using code like this:


Code:
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Public Function DownloadFile(ByVal URL As String, LocalFilename As String) As Boolean
    Dim lngRetVal As Long
    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    If lngRetVal = 0 Then DownloadFile = True
End Function


I then call this function with something like....


Code:
tech_skills = "[URL unfurl="true"]http://air.austar.com.au/pls/paytv/Skill_Type.xls?firstDate=01-SEP-03&rptDate=01-SEP-03&rptArea=Austar&p_params=%20skill_type_code"[/URL]

DownloadFile tech_skills, "C:\tech_skills.xls"
[code]
[/color]


Trouble is, POST methods don't accept query data the same way. I've tried adding a Microsfot Internet control (called Inet1) to a form and adding this code:

[COLOR=blue]
[code]
Private Sub download_button_click()

Dim vtData As Variant ' Data variable.
Dim intFile As Integer ' FreeFile variable
intFile = FreeFile()

Dim strURL As String, strFormData As String

strURL = "[URL unfurl="true"]http://luke.austar.com.au/cgi-bin/alliance/alliance_scheduled_work.cgi"[/URL]
strFormData = "management_area=WOL&date_range=05-SEP-2003&report_type=web"

Inet1.Execute strURL, "POST", strFormData

End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
   Dim vtData As Variant ' Data variable.
   Select Case State
   ' ... Other cases not shown.
   Case icResponseCompleted ' 12
      ' Open a file to write to.
      Open "C:\textfile.txt" For Binary Access Write As #intFile

      ' Get the first chunk. NOTE: specify a Byte
      ' array (icByteArray) to retrieve a binary file.
      vtData = Inet1.GetChunk(1024, icString)

      Do While LenB(vtData) > 0
         Put #intFile, , vtData
         ' Get next chunk.
         vtData = Inet1.GetChunk(1024, icString)
      Loop
      Put #intFile, , vtData
      Close #intFile
   End Select
End Sub


... but nothing seems to happen. The StateChanged event doesn't seem to get triggered. I have no issues with proxies or firewalls and I've tested the web page using my browser and am able to retrieve the page no trouble at all.

Looking for ideas if anybody has any.

Regards

Damien
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top