473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 "application / octet - stream"


Expand|Select|Wrap|Line Numbers
  1.  
  2. ' this function builds a http request bases on the following parameters:
  3. ' data = the data from the file to be uploaded
  4. ' DestUrl = a URL to containing information on where to send the data
  5. ' UploadName = the field upload name usually pass by <input type="file" name="uploadname"
  6. ' Filename = the name of the file
  7. ' The MIME type of the file
  8. Public Function BuildFileUploadRequest(ByRef strData As String, _
  9.                                         ByRef DestUrl As URL, _
  10.                                         ByVal UploadName As String, _
  11.                                         ByVal FileName As String, _
  12.                                         ByVal MimeType As String) As String
  13.  
  14.     Dim strHttp As String ' holds the entire HTTP request
  15.     Dim strBoundary As String 'the boundary between each entity
  16.     Dim strBody As String ' holds the body of the HTTP request
  17.     Dim lngLength As Long ' the length of the HTTP request
  18.  
  19.  
  20.     ' create a boundary consisting of a random string
  21.     strBoundary = RandomAlphaNumString(32)
  22.  
  23.     ' create the body of the http request in the form
  24.     '
  25.     ' --boundary
  26.     ' Content-Disposition: form-data; name="UploadName"; filename="FileName"
  27.     ' Content-Type: MimeType
  28.     '
  29.     ' file data here
  30.     '--boundary--
  31.     strBody = "--" & strBoundary & vbCrLf
  32.     strBody = strBody & "Content-Disposition: form-data; name=""" & UploadName & """; filename=""" & _
  33.                     FileName & """" & vbCrLf
  34.     strBody = strBody & "Content-Type: " & MimeType & vbCrLf '";CharSet=utf-8"
  35.     strBody = strBody & vbCrLf & strData
  36.     strBody = strBody & vbCrLf & "--" & strBoundary & "--"
  37.  
  38.  
  39.     ' find the length of the request body - this is required for the
  40.     ' Content-Length header
  41.      lngLength = Len(strBody)
  42.  
  43.     ' construct the HTTP request in the form:
  44.     '
  45.     ' POST /path/to/reosurce HTTP/1.0
  46.     ' Host: host
  47.     ' Content-Type: multipart-form-data;charset=utf-8, boundary=boundary
  48.     ' Content-Length: len(strbody)
  49.     '
  50.     ' HTTP request body
  51.     strHttp = "POST " & DestUrl.URI & "?" & DestUrl.Query & " HTTP/1.0" & vbCrLf
  52.     strHttp = strHttp & "Host: " & DestUrl.Host & vbCrLf
  53.     strHttp = strHttp & "Content-Type: multipart/form-data ;charset=utf-8, boundary=" & strBoundary & vbCrLf
  54.     strHttp = strHttp & "Content-Length: " & lngLength & vbCrLf & vbCrLf
  55.     strHttp = strHttp & strBody
  56.  
  57.     'Debug.Print LenB(strBoundary), LenB(strData), LenB(strBody), LenB(strHttp)
  58.  
  59.  
  60.     BuildFileUploadRequest = strHttp
  61.  
  62. End Function
  63.  
  64. ' this function retireves the contents of a file and returns it as a string
  65. ' this is also ture for binary files
  66. Public Function GetFileContents(ByVal strPath As String) As String
  67.     Dim StrReturn As String
  68.     Dim lngLength As Long
  69.  
  70.  
  71. On Error GoTo ERR_HANDLER
  72.  
  73.     lngLength = FileLen(strPath)
  74.  
  75.     StrReturn = String(lngLength, Chr(0))
  76.  
  77.     Open strPath For Binary As #1
  78.  
  79.     Get #1, , StrReturn
  80.  
  81.     GetFileContents = StrReturn
  82.  
  83.     Close #1
  84.  
  85.     Exit Function
  86.  
  87. ERR_HANDLER:
  88.     MsgBox Err.Description, vbCritical, "ERROR"
  89.  
  90.     Err.Clear
  91. End Function
Sep 21 '07 #1
0 1359

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dmitry Akselrod | last post by:
Hello everyone, I have a vb.net application that wraps the TCPListener object in a class. The server connects to the local interface and establishes itself on port 9900. It then polls for...
2
by: quotto | last post by:
I have written a web server application using ASP.Net that handles requests from an HTTP client. I wrote a small test client in VB6 using the MSINet ActiveX control, to load test the server. The...
7
by: Nadav | last post by:
Hi I am writing some kind of a storage system that have to deal with large amounts of data passing over the net, Now, I Wonder... traditional programming would use win32 Winsock DLL as the means...
1
by: Glen Conway | last post by:
Hi, I'm trying to use the gethostbyname function from wsock32.dll and failing dismally Has anyone got a successful implementation of this in VB.NET? My ulitimate goal is to resolve NetBIOS names...
5
by: kc | last post by:
Hi Just upgrading a app from VB6 to VB.Net. All is going well apart from the Winsock control. The first thing we notice is that there does not appear to be a .Net version (please correct me if...
9
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at...
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
2
by: =?Utf-8?B?R3JlZ0lJ?= | last post by:
Hi All, I have some problems with sending UDP packets using Winsock. I tried to send some to a closed port, and according to the documentation on Microsoft MSDN site...
4
by: imaloner | last post by:
I am posting two threads because I have two different problems, but both have the same background information. Common Background Information: I am trying to rebuild code for a working,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.