problem in upload through http winsock from non-english OS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpfreak2007
    New Member
    • Sep 2007
    • 31

    problem in upload through http winsock from non-english OS

    Hi all,
    I am trying to upload file using VB HTTP Post method and winsock control . Can successfully upload the files when client machine is English OS, but create problem when upload from Chinese OS. Currently what i am doing is reading file in string and then build a html request and send these string data to upload. fuction which read a file content and buildhttp request is given below.. can anyone suggest what is the problem. is it so because i am reading file in string or send the data as string??? or anything else?? i am using MIME type as "applicatio n / octet - stream"


    Code:
    ' this function builds a http request bases on the following parameters:
    ' data = the data from the file to be uploaded
    ' DestUrl = a URL to containing information on where to send the data
    ' UploadName = the field upload name usually pass by <input type="file" name="uploadname"
    ' Filename = the name of the file
    ' The MIME type of the file
    Public Function BuildFileUploadRequest(ByRef strData As String, _
                                            ByRef DestUrl As URL, _
                                            ByVal UploadName As String, _
                                            ByVal FileName As String, _
                                            ByVal MimeType As String) As String
        
        Dim strHttp As String ' holds the entire HTTP request
        Dim strBoundary As String 'the boundary between each entity
        Dim strBody As String ' holds the body of the HTTP request
        Dim lngLength As Long ' the length of the HTTP request
            
       
        ' create a boundary consisting of a random string
        strBoundary = RandomAlphaNumString(32)
        
        ' create the body of the http request in the form
        '
        ' --boundary
        ' Content-Disposition: form-data; name="UploadName"; filename="FileName"
        ' Content-Type: MimeType
        '
        ' file data here
        '--boundary--
        strBody = "--" & strBoundary & vbCrLf
        strBody = strBody & "Content-Disposition: form-data; name=""" & UploadName & """; filename=""" & _
                        FileName & """" & vbCrLf
        strBody = strBody & "Content-Type: " & MimeType & vbCrLf '";CharSet=utf-8"
        strBody = strBody & vbCrLf & strData
        strBody = strBody & vbCrLf & "--" & strBoundary & "--"
        
           
        ' find the length of the request body - this is required for the
        ' Content-Length header
         lngLength = Len(strBody)
        
        ' construct the HTTP request in the form:
        '
        ' POST /path/to/reosurce HTTP/1.0
        ' Host: host
        ' Content-Type: multipart-form-data;charset=utf-8, boundary=boundary
        ' Content-Length: len(strbody)
        '
        ' HTTP request body
        strHttp = "POST " & DestUrl.URI & "?" & DestUrl.Query & " HTTP/1.0" & vbCrLf
        strHttp = strHttp & "Host: " & DestUrl.Host & vbCrLf
        strHttp = strHttp & "Content-Type: multipart/form-data ;charset=utf-8, boundary=" & strBoundary & vbCrLf
        strHttp = strHttp & "Content-Length: " & lngLength & vbCrLf & vbCrLf
        strHttp = strHttp & strBody
    
        'Debug.Print LenB(strBoundary), LenB(strData), LenB(strBody), LenB(strHttp)
        
         
        BuildFileUploadRequest = strHttp
        
    End Function
    
    ' this function retireves the contents of a file and returns it as a string
    ' this is also ture for binary files
    Public Function GetFileContents(ByVal strPath As String) As String
        Dim StrReturn As String
        Dim lngLength As Long
        
        
    On Error GoTo ERR_HANDLER
        
        lngLength = FileLen(strPath)
        
        StrReturn = String(lngLength, Chr(0))
        
        Open strPath For Binary As #1
        
        Get #1, , StrReturn
        
        GetFileContents = StrReturn
        
        Close #1
        
        Exit Function
        
    ERR_HANDLER:
        MsgBox Err.Description, vbCritical, "ERROR"
        
        Err.Clear
    End Function
Working...