InetHttpSendForm example for Visual Basic
Take the following steps to use HTTP features to your application:
1. |
Start Visual Basic. |
2. |
Add the LEAD Raster Object Library and LEAD Raster Variant Object Library to your project. |
|
For VB5: On the Project pull-down menu, use the References option, and select the LEAD Raster Object Library (14.5). |
|
For VB5: On the Project pull-down menu, use the References option, and select the LEAD Raster Variant Object Library (14.5). |
3. |
Add the LEAD RasterIO Object Library to your project. |
|
For VB5: On the Project pull-down menu, use the References option, and select the LEAD RasterIO Object Library (14.5). |
4. |
Add the LEAD RasterHTTP Object Library to your project. |
|
For VB5: On the Project pull-down menu, use the References option, and select the LEAD RasterHTTP Object Library (14.5). |
5. |
Add the following lines to the General Declarations section at the top of your form's code: |
Dim HTTPObj As LEADRasterHTTP
Dim RasterObj As LEADRaster
Dim IOObj As LEADRasterIO
6. |
Add a command button to your form and name it as follows: |
|
|
Name |
Caption |
|
SendForm |
Send Form |
7. |
Add the following initialization code to the main form's Load procedure. In online help, you can use the Edit pull-down menu to copy the block of code. |
Private Sub Form_Load()
Set HTTPObj = CreateObject("LEADRasterHTTP.LEADRasterHTTP")
Set RasterObj = CreateObject("LEADRaster.LEADRaster")
Set IOObj = CreateObject("LEADRasterIO.LEADRasterIO")
HTTPObj.EnableMethodErrors =
False
End Sub
8. |
Code the SendForm button's click procedure as follows: |
Private Sub SendForm_Click()
Dim nRet As Integer, nStatus As Long
nRet = HTTPObj.InetHttpConnect
("demo.leadtools.com", 80, "", "")
If nRet = 0 Then
nRet = HTTPObj.InetHttpOpenRequest
(HTTP_RQST_POST, "/com/tutorial/http/form.asp ", "",
"HTTP/1.0")
If nRet = 0 Then
HTTPObj.InetHttpFormValueCount =
2
HTTPObj.InetHttpFormValues (0).pszName
= "email"
HTTPObj.InetHttpFormValues(0).pszValue
= "myemail@somewhere.com"
HTTPObj.InetHttpFormValues(1).pszName
= "name"
HTTPObj.InetHttpFormValues(1).pszValue
= "First Last"
nRet = HTTPObj.InetHttpSendForm ()
If nRet <>
0 Then
MsgBox
"Error Sending Form", vbOKOnly + vbExclamation, "Error"
HTTPObj.InetHttpCloseRequest
HTTPObj.InetHttpDisconnect
Exit
Sub
End If
HTTPObj.InetHttpGetServerStatus
nStatus
If nStatus = HTTP_STATUS_OK
Then
Dim
strResponse As String
strResponse
= HTTPObj.InetHttpGetResponse
Open
"c:\output.htm" For Binary As #1
Put
#1, , strResponse
Close
#1
Else
MsgBox
"Problem With Server", vbOK + vbExclamation, "Error"
End If
HTTPObj.InetHttpCloseRequest
HTTPObj.InetHttpDisconnect
End If
End If
End Sub
9. |
Run your program to test it. |
10. |
Save the project to use as a starting point for other tutorials. |