InetHttpSendRequest example for Visual Basic

1.

Start with a copy of the project that you created in InetHttpSendForm example for Visual Basic

2.

Add a command button to your form and name it as follows:

 

Name

Caption

 

SendRequest

Send Request

3.

Code the SendRequest button's click procedure as follows:

Private Sub SendRequest_Click()
   Dim nRet As Integer
   Dim RasterVar As LEADRasterVariant
   nRet = HTTPObj.InetHttpConnect("demo.leadtools.com", 80, "", "")
   If nRet = 0 Then
      nRet = HTTPObj.InetHttpOpenRequest(HTTP_RQST_GET, "/com/default.htm ", "", "HTTP/1.0")
      If nRet = 0 Then
         Dim strResponse As String
         Dim nStatus As Long
         RasterVar.StringValue = ""
         nRet = HTTPObj.InetHttpSendRequest(RasterVar, 0, RasterVar, 0)
         If nRet <> 0 Then
            MsgBox "Error Sending Form", vbExclamation, "Error"
            HTTPObj.InetHttpCloseRequest
            HTTPObj.InetHttpDisconnect
            Exit Sub
         End If
         nStatus = HTTPObj.InetHttpGetServerStatus
         If nStatus = HTTP_STATUS_OK Then
            strResponse = HTTPObj.InetHttpGetResponse()
            Kill "c:\output.htm"
            Open "c:\output.htm" For Binary As #1
            Put #1, , strResponse
            Close #1
         Else
            MsgBox "Problem With Server", vbExclamation, "Error"
            strResponse = HTTPObj.InetHttpGetResponse()
            Open "c:\error.htm" For Binary As #1
            Put #1, , strResponse
            Close #1
         End If
         HTTPObj.InetHttpCloseRequest
      End If
      HTTPObj.InetHttpDisconnect
   End If
End Sub

4.

Run your program to test it.