Solved

Running an http request

Posted on 2000-04-07
4
180 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now