InetHttpSendData 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

 

SendData

Send Data

3.

Code the SendData button's click procedure as follows:

Private Sub SendData_Click()
   Dim nRet As Integer
   Dim i As Integer
   nRet = HTTPObj.InetHttpConnect("demo.leadtools.com", 80, "", "")
   If nRet = 0 Then
      nRet = HTTPObj.InetHttpOpenRequest(HTTP_RQST_GET, "/com/tutorial/http/upload.asp ", "", "HTTP/1.0")
      If nRet = 0 Then
         Dim strResponse As String
         Dim nStatus As Long
         Dim nv As NAMEVALUEItem
         Dim RasterVar As LEADRasterVariant

         RasterVar.Type = VALUE_ARRAY_BYTE
         RasterVar.ItemCount = 1000
         For i = 0 To 999
            RasterVar.ShortItemValue(i) = 65 + i / 10
         Next i
         Set nv = CreateObject("NAMEVALUEItem.NAMEVALUEItem.121")
         nv.pszName = "Data"
         nv.pszValue = "data1.raw"
         nRet = HTTPObj.InetHttpSendData(RasterVar, 1000, "image/jpg", nv)
         If nRet <> 0 Then
            MsgBox "Error Sending Data", 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.