473,395 Members | 1,639 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,395 software developers and data experts.

HTTP Form Post

LD
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.ToString(Chr(13)) + Convert.ToString(Chr(10))
Dim vbCr As String = Convert.ToString(Chr(13))
Dim vbLf As String = Convert.ToString(Chr(10))
Dim boundary As String = "-----------------------------7d31151970286"

Dim myWebClient As New System.Net.WebClient()
Dim URL As String
Dim body As String
Dim body2 As String

'============READ 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.Headers.Add("Accept", "image/gif, image/x-xbitmap, image/jpeg,
image/pjpeg, application/vnd.ms-excel, application/msword,
application/x-shockwave-flash, */*")
myWebClient.Headers.Add("Accept-Language", "en-us")
myWebClient.Headers.Add("Content-Type", "multipart/form-data; boundary=" +
boundary)
myWebClient.Headers.Add("Accept-Encoding", "gzip, deflate")
myWebClient.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.1; Q312461; .NET CLR 1.0.3705)")
myWebClient.Headers.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.Encoding.Default.GetBytes(body)
byte2 = System.Text.Encoding.Default.GetBytes(body2)

'===========JOIN BODY AND FILE CONENTS============
Dim pobjCombinedArrays = New ArrayList(byte1.Length + Tem.Length +
byte2.Length)

'Append the arrays here.
pobjCombinedArrays.AddRange(byte1)
pobjCombinedArrays.AddRange(Tem)
pobjCombinedArrays.AddRange(byte2)

Dim pbytCombinedArrays(pobjCombinedArrays.Count) As Byte
pobjCombinedArrays.CopyTo(pbytCombinedArrays)

'===========POST DATA AND GET RESPONSE============
Dim bResponse As Byte() = myWebClient.UploadData(URL, "POST",
pobjCombinedArrays)

Response.Write(System.Text.Encoding.ASCII.GetStrin g(bResponse))


Nov 20 '05 #1
2 6011
Cor
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.uploadfile methode to.
I hope this helps a little bit.
Cor
Nov 20 '05 #2
"LD" <he**@home.com> schrieb:
Dim vbCrLf As String = Convert.ToString(Chr(13)) + Convert.ToString(Chr(10)) Dim vbCr As String = Convert.ToString(Chr(13))
Dim vbLf As String = Convert.ToString(Chr(10))


The constants above are already defined in the
'Microsoft.VisualBasic.Constants' class.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
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...
8
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...
6
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"...
1
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...
0
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...
0
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...
0
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...
6
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...
2
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 ...
0
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.