Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - ASP.NET HTTP Form Post using UploadData M
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

ASP.NET HTTP Form Post using UploadData M

 Post Reply Post Reply
Author
rivers870 View Drop Down
Newbie
Newbie


Joined: 05 September 2003
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote rivers870 Quote  Post ReplyReply Direct Link To This Post Topic: ASP.NET HTTP Form Post using UploadData M
    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))
Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 06 September 2003 at 3:58am

No really, maybe add

If Page.IsPostBack = False Then

  ...

Else

  Exit Sub

End If

Gone..
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.