Form Post

Discussion in 'ASP .Net Web Controls' started by LD, Sep 5, 2003.

  1. LD

    LD Guest

    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.GetString(bResponse))
     
    LD, Sep 5, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TNG
    Replies:
    2
    Views:
    2,349
  2. botdf

    Get POST information from <form>......</form>

    botdf, Jan 26, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    181
    Joerg Jooss
    Jan 29, 2005
  3. Don Glover the younger

    ASP, FORMS, POST METHOD And Post with out form(???)

    Don Glover the younger, Jul 13, 2003, in forum: ASP General
    Replies:
    0
    Views:
    472
    Don Glover the younger
    Jul 13, 2003
  4. J. Muenchbourg
    Replies:
    0
    Views:
    366
    J. Muenchbourg
    Aug 6, 2003
  5. Adam
    Replies:
    8
    Views:
    426
Loading...

Share This Page