Hi,
I am trying to upload a zip file and other form data elements to a server
and get a response. The server keeps responding with Malformed Multipart
Post. Can
anyone see what might be wrong here? Any feedback much appreciated.
Dim vbCrLf As String = Convert.ToStrin g(Chr(13)) + Convert.ToStrin g(Chr(10))
Dim vbCr As String = Convert.ToStrin g(Chr(13))
Dim vbLf As String = Convert.ToStrin g(Chr(10))
Dim boundary As String = "-----------------------------7d31151970286"
Dim myWebClient As New System.Net.WebC lient()
Dim URL As String
Dim body As String
Dim body2 As String
'============RE AD FILE CONTENTS INTO BYTE ARRAY========== ==
Dim Tem() As Byte
Dim st As FileStream = File.OpenRead(" data.zip")
ReDim Tem(st.Length)
Do While st.Position < st.Length
st.Read(Tem, 0, Tem.Length - 1)
Loop
st.Close()
'============== ====SET HEADERS======== ==============
myWebClient.Hea ders.Add("Accep t", "image/gif, image/x-xbitmap, image/jpeg,
image/pjpeg, application/vnd.ms-excel, application/msword,
application/x-shockwave-flash, */*")
myWebClient.Hea ders.Add("Accep t-Language", "en-us")
myWebClient.Hea ders.Add("Conte nt-Type", "multipart/form-data; boundary=" +
boundary)
myWebClient.Hea ders.Add("Accep t-Encoding", "gzip, deflate")
myWebClient.Hea ders.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.1; Q312461; .NET CLR 1.0.3705)")
myWebClient.Hea ders.Add("Cache-Control", "no-cache")
'============== ====CREATE BODY=========== ===========
body = boundary & vbCrLf & _
"Content-Disposition: " & "form-data; name=""username """ & vbCrLf & vbCrLf &
_
"username" & vbCrLf
body = body & boundary & vbCrLf & _
"Content-Disposition: " & "form-data; name=""password """ & vbCrLf & vbCrLf &
_
"password" & vbCrLf
body = body & boundary & vbCrLf & _
"Content-Disposition: " & "form-data; name=""client"" " & vbCrLf & vbCrLf & _
"client" & vbCrLf
body = body & boundary & vbCrLf & _
"Content-Disposition: " & "form-data; name=""data""" & ";
filename=""data .zip""" & vbCrLf & _
"Content-Type: application/x-zip-compressed" & vbCrLf & vbCrLf
body2 = vbCrLf & boundary & "--"
Dim byte1 As Byte()
Dim byte2 As Byte()
byte1 = System.Text.Enc oding.Default.G etBytes(body)
byte2 = System.Text.Enc oding.Default.G etBytes(body2)
'===========JOI N BODY AND FILE CONENTS======== ====
Dim pobjCombinedArr ays = New ArrayList(byte1 .Length + Tem.Length +
byte2.Length)
'Append the arrays here.
pobjCombinedArr ays.AddRange(by te1)
pobjCombinedArr ays.AddRange(Te m)
pobjCombinedArr ays.AddRange(by te2)
Dim pbytCombinedArr ays(pobjCombine dArrays.Count) As Byte
pobjCombinedArr ays.CopyTo(pbyt CombinedArrays)
'===========POS T DATA AND GET RESPONSE======= =====
Dim bResponse As Byte() = myWebClient.Upl oadData(URL, "POST",
pobjCombinedArr ays)
Response.Write( System.Text.Enc oding.ASCII.Get String(bRespons e)) 2 6020
Hi,
Just a quick look and maybe I am wrong, Dim st As FileStream = File.OpenRead(" data.zip")
Are you sure this instruction finds the right text file in the zip?
Maybe you know, but if not, there is a webclient.uploa dfile methode to.
I hope this helps a little bit.
Cor
"LD" <he**@home.co m> schrieb: Dim vbCrLf As String = Convert.ToStrin g(Chr(13)) +
Convert.ToStrin g(Chr(10)) Dim vbCr As String = Convert.ToStrin g(Chr(13)) Dim vbLf As String = Convert.ToStrin g(Chr(10))
The constants above are already defined in the
'Microsoft.Visu alBasic.Constan ts' class.
--
Herfried K. Wagner
MVP · VB Classic, VB.NET http://www.mvps.org/dotnet This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dave Smithz |
last post by:
Hi there,
I have a situation where I want to have multiple submit buttons on the same
form and therefore want to use a redirection php script that checks the
value associated with the submit form variable to calculate which submit was
pressed and then redirects the user to another php page accordingly.
I used:
headers...
|
by: bmgx |
last post by:
I would like to use an already existing online service (currency
converter) basically consisting of a html form with a few options that
is submitted and returns the results. I really don't know where to start
but I have assumed the following steps need to be taken:
1) Make an http connection to the remote script (http://server/script.cgi)
...
|
by: Phillip N Rounds |
last post by:
I have a webform, from which I have to submit info to another site. Their
instructions are to have a html form, with the following as the submit:
<form method="post" action="http://www.theirsite.htm">
<input type=hidden name="field1" value="value1">
<input type=hidden name="field2> value="value2>
<input type="submit" value="Click Me">
On...
|
by: Dan Corkum |
last post by:
Good morning. I am working on an issue that is just baffling me. I have
developed an .aspx page that receives an http form post that has a "file"
attribute.
When I do testing with a test post page, everything functions properly. When
the actual customer does the post, the attribute following the "file"
attribute is concatenated to the file...
|
by: Dan Corkum |
last post by:
Good morning. I am working on an issue that is just baffling me. I have
developed an .aspx page that receives an http form post that has a "file"
attribute.
When I do testing with a test post page, everything functions properly. When
the actual customer does the post, the attribute following the "file"
attribute is concatenated to the file...
| |
by: Owen |
last post by:
Hello everyone,
I am using VS.NET 2003(Trandition Chinese) Edition, and httpLook
software for checking http requests. I found a problem that the
following programs don't really "POST". These programs can be
successfully compiled. There is no error message shown at running
also. But the httpLook confirms that the program doesn't post....
|
by: WIWA |
last post by:
Hi,
I want to login to a password protected website and fetch the content of the
page behind. I have based my code on
http://weblogs.asp.net/jdennany/archive/2005/04/23/403971.aspx. When I use
tools like ieHTTPHeaders v1.6, and I perform a normal login (using the
normal website), I see that the viewstate is...
|
by: Brybot |
last post by:
I am trying to allow HTTP POST file uploads to my web service.
Currently I have it working perfectly for a SOAP/XML request reading
in a byte using MemoryStream/FileStream but I cannot figure out how
to encode a file on a POST to the same web service. The definition
requires a base64binary encoded file, which I have tried. The form is
also...
|
by: MDANH2002 |
last post by:
Hi
From VB.NET I want to simulate the POST request of the following HTML form
<html>
<title>HTTP Post Testing</title>
<body>
<form action=http://www.example.com/postdata
enctype="multipart/form-data" method="post" name="testform">
|
by: shlim |
last post by:
Currently I'm using VB.Net to perform a http/https multipart form post to a servlet. I'm able to perform the post using HttpWebrequest via GetRequestStream(). However, the servlet returned me with "The remote server returned an error: (500) Internal Server Error". Obviously, this means that I have not posted all the parameters as the servlet...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |