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_SIZE - 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_RELOAD, 0)
If hRequest = 0 Then
LastDllErrorInfo '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_SIZE, 0)
blnSendRequest = HttpSendRequest(hRequest, vbNullString, 0, 0, 0)
HTTP_QUERY_CONTENT_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 = InternetWriteFile(hRequest, bData(0), Len(bData(0)), lWritten)
If nRet = 0 Then
LastDllErrorInfo 'Call before calling any other dll function
If Not HttpErrorCode = 0 Then
Err.Raise HttpErrorCode, , HttpErrorString
End If
Exit Function
End If
End If
InternetCloseHandle hRequest
InternetCloseHandle hConnect
InternetCloseHandle hInternet
End Function