VB Upload File - Chinese OS
Hi Guys,
Me trying to upload file using VB HTTP Post method. Can successfully upload the files when my client machine is English OS . However , the problem occurs when am trying to upload the files from Chinese OS. It seems that the file uploaded is getting corrupted and could not be opened in correct format. This is applicable for binary files. The text files could be uploaded successfully.
I have tried setting content-type, charset,codepage etc properties to assemble the body.
Can anyone help me ? Its urgent ....Hope to find some VB GURU in this group.HELP !
part of the code :
==========================
Sub uploadFile(a_strUserName As String, a_strUserPassword As String, a_strServerURL As String, a_strFilename As String, a_strFileTitle)
On Error GoTo err_uploadFile Const HTTPREQUEST_PROXYSETTING_DEFAULT = 0
Const HTTPREQUEST_PROXYSETTING_PRECONFIG = 0
Const HTTPREQUEST_PROXYSETTING_DIRECT = 1
Const HTTPREQUEST_PROXYSETTING_PROXY = 2
Const HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0 ' WinHTTPRequest options
Const HTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1
Const WinHttpRequestOption_UserAgentString = 0
Const WinHttpRequestOption_URL = 1
Const WinHttpRequestOption_URLCodePage = 2
Const WinHttpRequestOption_EscapePercentInURL = 3
Const WinHttpRequestOption_SslErrorIgnoreFlags = 4
Const WinHttpRequestOption_SelectCertificate = 5
Const WinHttpRequestOption_EnableRedirects = 6
Const WinHttpRequestOption_UrlEscapeDisable = 7
Const WinHttpRequestOption_UrlEscapeDisableQuery = 8
Const WinHttpRequestOption_SecureProtocols = 9
Const WinHttpRequestOption_EnableTracing = 10
Const SslErrorFlag_Ignore_All = 13056 Const HTTP_STATUS_PROXY_AUTH_REQ = 407
Const HTTP_STATUS_DENIED = 401
Const HTTP_STATUS_OK = 200
Dim strFile As String
Dim strURL As String
Dim strBody As String
Dim aPostBody() As Byte
Dim nFile As Integer
' Read the file from the hard disk ''' Dim w_objWinHttpRequest As New WinHttp.WinHttpRequest ''' Set g_objWinHttpRequest = CreateObject("WinHttp.WinHttpRequest.5.1") w_strProxyURL = getProxyURL()
nFile = FreeFile
Open a_strFilename For Binary As #nFile
strFile = String(LOF(nFile), " ")
Get #nFile, , strFile
Close #nFile
Dim w_strRequestURL As String
Dim w_strProxyURL As String
If Len(w_strProxyURL) > 0 Then End If
g_objWinHttpRequest.SetProxy HTTPREQUEST_PROXYSETTING_PROXY, w_strProxyURL, getProxyByPassServerList()
w_strRequestURL = a_strServerURL & JSP_FILE_UPLOAD
g_objWinHttpRequest.SetTimeouts 0, 0, 0, 0 g_objWinHttpRequest.Open "POST", w_strRequestURL, False ' Set the header < here i have tried setting the charset , codepage parameters too but of little use as on the server 'side the extraction of the zip file is not done according to the given encoding method.> ' Assemble the body ' Because of binary zeros, post body has to convert to byte array WriteToLogFile ("strbody :" & strBody & " localeid: " & g_lngLocaleID) g_objWinHttpRequest.Option(WinHttpRequestOption_EnableHttpsToHttpRedirects) = True g_objWinHttpRequest.Option(WinHttpRequestOption_SelectCertificate) = True g_objWinHttpRequest.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All g_objWinHttpRequest.SetClientCertificate "LOCAL_MACHINE\Other People" If g_objWinHttpRequest.Status = HTTP_STATUS_DENIED Then End If Exit Sub err_uploadFile:
g_objWinHttpRequest.SetRequestHeader "Content-Type", "multipart/form-data; boundary=Xu02=$"
strBody = "--Xu02=$" & vbCrLf & _
"Content-Disposition: form-data; name=""TestFile""; filename=""" & a_strFileTitle & """" & vbCrLf & _
"Content-type: file" & vbCrLf & vbCrLf & _
strFile & vbCrLf & _
"--Xu02=$--"
aPostBody = StrConv(strBody, vbFromUnicode, g_lngLocaleID) 'vbFromUnicode
g_objWinHttpRequest.Send aPostBody 'posts the body to JSP.
g_objWinHttpRequest.SetCredentials a_strUserName, a_strUserPassword, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
g_objWinHttpRequest.Send aPostBody
m_ErrorDesc = "err_uploadFile [ERROR] : " & err.Description End Sub
m_ErrorFlag = True
WriteToLogFile "err_uploadFile [ERROR] : " & err.Description
==========================
Thanks in advance,
Ashish.0.

