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" -
-
' 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
0 1359 Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |