Running an http request

With the fewest number of references (no controls), how can I run an URL from VB ? I don't actually need to retrieve data as the URL runs some kind of Java applet that transfers data within the URL string to a database.

Thanks,

Tim
timjcAsked:
Who is Participating?
 
Erick37Connect With a Mentor Commented:
The easiest way would be to use the Internet Transfer Control - but you said no controls.

Take a look at this code which uses the Internet API functions:

"Post or Request Data To/From a Web Server without a Web Browser"
http://www.freevbcode.com/ShowCode.Asp?ID=856
0
 
riduceCommented:
Hope this is you're answer
http://www.freevbcode.com/code/CGI.zip

Good luck
Riduce
0
 
ATMCommented:
POST/GET via PROXY or Directly, Virtual Hosts.
Only one exception from your request its use WinSock.OCX.

'------------------------------------------------------------
Public JobURL As String
Public JobParams As String
Public JobMethod As String
Public JobReferer As String
Public ResponseDocument As String
Public StepCount As Long
Public IsProxyUsed As Boolean
Public ServerHostIP As String
Public ServerPort As Long

'------------------------------------------------------------
Dim LocalStepCounter As Long
Dim RequestHeader As String
Dim RequestTemplate As String
'------------------------------------------------------------

Public Sub ActionStartup()
   
  FrmMainWin.DefSubmissionCompleted = False
 
  If UCase(Left(JobURL, 7)) <> "HTTP://" Then
     MsgBox "Missed http://, please check Your DB for proper Submission URLs", vbCritical + vbOK
     Call ActionPostup
     Me.Hide
     Unload Me
     Exit Sub
  End If
   
  LocalStepCounter = 0
  RequestHeader = ""
  RequestTemplate = JobMethod & " _$-$_$- HTTP/1.0" & Chr(13) & Chr(10) & _
                "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/x-comet, */*" & Chr(13) & Chr(10) & _
                "Accept-Language: en" & Chr(13) & Chr(10) & _
                "Accept-Encoding: gzip , deflate" & Chr(13) & Chr(10) & _
                "Cache-Control: no-cache" & Chr(13) & Chr(10) & _
                "Proxy-Connection: Keep-Alive" & Chr(13) & Chr(10) & _
                "User-Agent: Mozilla/4.0 (compatible; MSIE 5.1; Windows 98; SSM Agent 1.0)" & Chr(13) & Chr(10) & _
                "Host: @$@@$@" & Chr(13) & Chr(10)
               
  If JobMethod = "POST" Then
     RequestTemplate = RequestTemplate & "Content-Type: application/x-www-form-urlencoded" & Chr(13) & Chr(10)
     RequestTemplate = RequestTemplate & "Content-Length: " & CStr(Len(JobParams)) & Chr(13) & Chr(10)
     RequestTemplate = RequestTemplate & Chr(13) & Chr(10)
     RequestTemplate = RequestTemplate & JobParams & Chr(13) & Chr(10) & Chr(13) & Chr(10)
  Else
     JobURL = JobURL & "?" & JobParams
  End If
   
  pureURL = Right(JobURL, Len(JobURL) - 7)
  startPos = InStr(1, pureURL, "/")
 
  If startPos < 1 Then
     Serveraddress = pureURL
     documentURI = "/"
  Else
     Serveraddress = Left(pureURL, startPos - 1)
     documentURI = Right(pureURL, Len(pureURL) - startPos + 1)
  End If
     
  If Serveraddress = "" Or documentURI = "" Then
     MsgBox "Unable to detect target page!", vbCritical + vbOK
     FrmActionWait.Hide
     Unload FrmActionWait
     Exit Sub
  End If
 
  If IsProxyUsed Then
     
      If ServerHostIP = "" Then
         MsgBox "Unable to detect proxy address!", vbCritical + vbOK
         FrmActionWait.Hide
         Unload FrmActionWait
         Exit Sub
      End If
      RequestHeader = RequestTemplate
      RequestHeader = Replace(RequestHeader, "@$@@$@", Serveraddress)
      RequestHeader = Replace(RequestHeader, "_$-$_$-", JobURL)
  Else
      ddotsPos = 0
      tmpPString = ""
      ddotsPos = InStr(1, Serveraddress, ":")
      If ddotsPos = 0 Then
         ServerHostIP = Serveraddress
         ServerPort = 80
      Else
         ServerHostIP = Mid(Serveraddress, 1, ddotsPos - 1)
         tmpPString = Mid(Serveraddress, ddotsPos + 1, Len(Serveraddress) - ddotsPos - 1)
         If IsNumeric(tmpPString) Then
            ServerPort = CLng(tmpPString)
         Else
            ServerPort = 80
         End If
      End If
     
      RequestHeader = RequestTemplate
      RequestHeader = Replace(RequestHeader, "_$-$_$-", documentURI)
      RequestHeader = Replace(RequestHeader, "@$@@$@", ServerHostIP)
  End If
 
  'Me.Show
  RequestHeader = RequestHeader & Chr(13) & Chr(10)
  FrmMainWin.txtSubmitStatus.Text = "Connecting to server ..."
  FrmMainWin.txtSubmitStatus.Refresh
   
 If DEBON Then
  Open App.Path & "\Submission.log" For Append As #1
          Print #1, "-- " & DefData.ssmEngine & " --, " & ServerHostIP & ":" & ServerPort & Chr(13) & Chr(10)
          Print #1, RequestHeader
  Close #1
 End If
 
 'False
 WS_HTTP.Connect ServerHostIP, ServerPort
End Sub



Private Sub WS_HTTP_Connect()
 
 WS_HTTP.SendData RequestHeader
 
 If DEBON Then
  Open App.Path & "\Submission.log" For Append As #1
          Print #1, "-- CONNECTED/A --" & Chr(13) & Chr(10)
  Close #1
 End If
 
 FrmMainWin.txtSubmitStatus.Text = "Connected, try to submit page ..."
 FrmMainWin.txtSubmitStatus.Refresh
 
End Sub

Private Sub WS_HTTP_DataArrival(ByVal bytesTotal As Long)
 
 Dim tmpString As String
 WS_HTTP.GetData tmpString, vbString
 
 If DEBON Then
  Open App.Path & "\Submission.log" For Append As #1
          Print #1, "-- RESPONSE --" & Chr(13) & Chr(10)
          Print #1, tmpString
  Close #1
 End If
   
 FrmMainWin.txtSubmitStatus.Text = "Server response, continue ..."
 FrmMainWin.txtSubmitStatus.Refresh
 
End Sub

Private Sub WS_HTTP_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
 
 WS_HTTP.Close
   
 If DEBON Then
  Open App.Path & "\Submission.log" For Append As #1
          Print #1, "-- ERROR/A: " & Number & " --" & Chr(13) & Chr(10)
  Close #1
 End If
 
 Call ActionPostup
 
 FrmMainWin.txtSubmitStatus.Text = "Completing submission ..."
 FrmMainWin.txtSubmitStatus.Refresh
     
End Sub

Private Sub WS_HTTP_Close()
 
 WS_HTTP.Close
 
 If DEBON Then
  Open App.Path & "\Submission.log" For Append As #1
          Print #1, "-- CLOSED --" & Chr(13) & Chr(10)
  Close #1
 End If

 Call ActionPostup
 
 FrmMainWin.txtSubmitStatus.Text = "Completing submission ..."
 FrmMainWin.txtSubmitStatus.Refresh
     
End Sub

Public Sub ActionPostup()
   
  FrmMainWin.DefSubmissionCompleted = True
   
End Sub

0
 
timjcAuthor Commented:
Nice answers by all experts. I thought that Erick37 was the quickest to use. I can't split points, so had to choose one, apologies to others.
0
All Courses

From novice to tech pro — start learning today.