I am facing problem in HttpSendRequest () API(Developing OCX for Http Upload control.).It always return false.Any idea?I am posting my code:
Public Function UploadFileHTTP( ByVal localFileName As String, ByVal remoteFileName As String) As Integer
Dim nRet As Integer
Dim nFileHandle As Integer
Dim bData(BUFFER_SI ZE - 1) As Byte
Dim leftoversize As Long
lWritten = 0
Dim blnSendRequest As Boolean
Dim remoteFileSize As Long
Dim sData As String
nFileHandle = FreeFile
hRequest = HttpOpenRequest (hConnect, "PUT", remoteFileName, "HTTP/1.0", vbNullString, 0, INTERNET_FLAG_R ELOAD, 0)
If hRequest = 0 Then
LastDllErrorInf o 'Call before calling any other dll function
If Not HttpErrorCode = 0 Then
Err.Raise HttpErrorCode, , HttpErrorString
End If
Exit Function
End If
sData = String(BUFFER_S IZE, 0)
blnSendRequest = HttpSendRequest (hRequest, vbNullString, 0, 0, 0)
HTTP_QUERY_CONT ENT_LENGTH, sData, Len(sData))
'Read data from local buffer
Open localFileName For Binary Access Read As nFileHandle 'Open the source file (localFileName) for read access
nLOF = LOF(nFileHandle ) 'Create a buffer that will hold the contents of the file
leftoversize = nLOF
If leftoversize <> 0 Then
Get nFileHandle, , bData 'Read the contents of the file into the buffer.
'Write to server
nRet = InternetWriteFi le(hRequest, bData(0), Len(bData(0)), lWritten)
If nRet = 0 Then
LastDllErrorInf o 'Call before calling any other dll function
If Not HttpErrorCode = 0 Then
Err.Raise HttpErrorCode, , HttpErrorString
End If
Exit Function
End If
End If
InternetCloseHa ndle hRequest
InternetCloseHa ndle hConnect
InternetCloseHa ndle hInternet
End Function
Public Function UploadFileHTTP( ByVal localFileName As String, ByVal remoteFileName As String) As Integer
Dim nRet As Integer
Dim nFileHandle As Integer
Dim bData(BUFFER_SI ZE - 1) As Byte
Dim leftoversize As Long
lWritten = 0
Dim blnSendRequest As Boolean
Dim remoteFileSize As Long
Dim sData As String
nFileHandle = FreeFile
hRequest = HttpOpenRequest (hConnect, "PUT", remoteFileName, "HTTP/1.0", vbNullString, 0, INTERNET_FLAG_R ELOAD, 0)
If hRequest = 0 Then
LastDllErrorInf o 'Call before calling any other dll function
If Not HttpErrorCode = 0 Then
Err.Raise HttpErrorCode, , HttpErrorString
End If
Exit Function
End If
sData = String(BUFFER_S IZE, 0)
blnSendRequest = HttpSendRequest (hRequest, vbNullString, 0, 0, 0)
HTTP_QUERY_CONT ENT_LENGTH, sData, Len(sData))
'Read data from local buffer
Open localFileName For Binary Access Read As nFileHandle 'Open the source file (localFileName) for read access
nLOF = LOF(nFileHandle ) 'Create a buffer that will hold the contents of the file
leftoversize = nLOF
If leftoversize <> 0 Then
Get nFileHandle, , bData 'Read the contents of the file into the buffer.
'Write to server
nRet = InternetWriteFi le(hRequest, bData(0), Len(bData(0)), lWritten)
If nRet = 0 Then
LastDllErrorInf o 'Call before calling any other dll function
If Not HttpErrorCode = 0 Then
Err.Raise HttpErrorCode, , HttpErrorString
End If
Exit Function
End If
End If
InternetCloseHa ndle hRequest
InternetCloseHa ndle hConnect
InternetCloseHa ndle hInternet
End Function