Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Form Post

Reply
Thread Tools

Form Post

 
 
LD
Guest
Posts: n/a
 
      09-05-2003
Hi,

I am trying to upload a 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))




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Form Post Using Javascript - Empty Post from FF Adam Javascript 8 11-24-2005 12:03 PM
Post Form with Variable of the form itself TNG HTML 2 03-03-2005 05:34 PM
Post post post. Shel-hed Computer Support 2 11-08-2003 07:41 AM
Can post form data in IIS, but doesnt post it via webserver J. Muenchbourg Javascript 0 08-06-2003 05:23 PM
ASP, FORMS, POST METHOD And Post with out form(???) Don Glover the younger ASP General 0 07-13-2003 02:47 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57