Solved

Running an http request

Posted on 2000-04-07
4
184 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:timjc
4 Comments
 
LVL 1

Expert Comment

by:riduce
ID: 2694020
Hope this is you're answer
http://www.freevbcode.com/code/CGI.zip

Good luck
Riduce
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 150 total points
ID: 2694055
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
 
LVL 1

Expert Comment

by:ATM
ID: 2694182
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
 

Author Comment

by:timjc
ID: 2694245
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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question