Print Page | Close Window

ASP.NET HTTP Form Post using UploadData M

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=5549
Printed Date: 29 March 2026 at 10:42am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: ASP.NET HTTP Form Post using UploadData M
Posted By: rivers870
Subject: ASP.NET HTTP Form Post using UploadData M
Date Posted: 05 September 2003 at 10:21am
Hi,

I am trying to upload a zip file with other form data elements to a remote 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.GetString(bRespons e))



Replies:
Posted By: Diep-Vriezer
Date Posted: 06 September 2003 at 3:58am

No really, maybe add

If Page.IsPostBack = False Then

  ...

Else

  Exit Sub

End If



-------------
Gone..



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net