Results 1 to 4 of 4

Thread: VB Upload file Chinese OS - HTTP Post body Method- HELP !

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Location
    Mumbai
    Posts
    7

    VB Upload file Chinese OS - HTTP Post body Method- HELP !

    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 !

    Thanks in advance,
    Ashish.0.


    Part of the code :

    --------------------------------------------

    Sub uploadFile(a_strUserName As String, a_strUserPassword As String, a_strDigiteServerURL 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
    Const HTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1

    ' WinHTTPRequest options
    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
    nFile = FreeFile
    Open a_strFilename For Binary As #nFile
    strFile = String(LOF(nFile), " ")
    Get #nFile, , strFile
    Close #nFile

    ''' Dim w_objWinHttpRequest As New WinHttp.WinHttpRequest
    Dim w_strRequestURL As String
    Dim w_strProxyURL As String

    ''' Set g_objWinHttpRequest = CreateObject("WinHttp.WinHttpRequest.5.1")

    w_strProxyURL = getProxyURL()

    If Len(w_strProxyURL) > 0 Then
    g_objWinHttpRequest.SetProxy HTTPREQUEST_PROXYSETTING_PROXY, w_strProxyURL, getProxyByPassServerList()

    End If

    w_strRequestURL = a_strDigiteServerURL & 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.>
    g_objWinHttpRequest.SetRequestHeader "Content-Type", "multipart/form-data; boundary=Xu02=$"

    ' Assemble the body
    strBody = "--Xu02=$" & vbCrLf & _
    "Content-Disposition: form-data; name=""TestFile""; filename=""" & a_strFileTitle & """" & vbCrLf & _
    "Content-type: file" & vbCrLf & vbCrLf & _
    strFile & vbCrLf & _
    "--Xu02=$--"

    ' Because of binary zeros, post body has to convert to byte array
    aPostBody = StrConv(strBody, vbFromUnicode, g_lngLocaleID) 'vbFromUnicode

    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"
    g_objWinHttpRequest.Send aPostBody 'posts the body to JSP.

    If g_objWinHttpRequest.Status = HTTP_STATUS_DENIED Then
    g_objWinHttpRequest.SetCredentials a_strUserName, a_strUserPassword, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
    g_objWinHttpRequest.Send aPostBody

    End If

    Exit Sub

    err_uploadFile:

    m_ErrorDesc = "err_uploadFile [ERROR] : " & err.Description
    m_ErrorFlag = True
    WriteToLogFile "err_uploadFile [ERROR] : " & err.Description

    End Sub



    ---------------------------------------------

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB Upload file Chinese OS - HTTP Post body Method- HELP !

    Moved from the Codebank

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: VB Upload file Chinese OS - HTTP Post body Method- HELP !

    Load the file into a byte array, not a string variable (strFile). If you want it as a Unicode string later you can convert it using StrConv().
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Location
    Mumbai
    Posts
    7

    Re: VB Upload file Chinese OS - HTTP Post body Method- HELP !

    tried...hard luck :-(

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width