Windows Form upload data file by HTTP POST menu

Shout-Out

User Tag List

Results 1 to 2 of 2
  1. #1
    secureecs's Avatar Member
    Reputation
    -3
    Join Date
    Jan 2007
    Posts
    63
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Windows Form upload data file by HTTP POST

    Hi,

    I would like to send a jpg file to a HTTP server by POST request. But I am
    not using a browser to do this, I use a Windows Form instead. I know how to
    send typical request by POST with code below. But I don't know how to encode
    the data file so the server can be recognized.

    1 ) Traditional HTML code for upload a file:
    <form action="http://abc.com/save_photos.php" name="upload_form"
    enctype="multipart/form-data" method="POST">

    2 ) My vb.net code for POST request:
    Dim lcUrl As String = "http://abc.com/save_photos.php"
    Dim myHttpWebRequest As HttpWebRequest =
    DirectCast(WebRequest.Create(lcUrl), HttpWebRequest)
    myHttpWebRequest.Method = "POST"

    ' Create a new string object to POST data to the Url.
    Dim inputData As String = "cmd=" & HttpUtility.UrlEncode("login")

    Dim postData As String = inputData
    Dim encoding As New ASCIIEncoding
    Dim byte1 As Byte() = encoding.GetBytes(postData)

    ' Set the content type of the data being posted.
    myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"

    'Do I need to set cotnet type as below if transfer data file?
    'myHttpWebRequest.ContentType = "multipart/form-data encode"


    ' Set the content length of the string being posted.
    myHttpWebRequest.ContentLength = postData.Length
    Dim newStream As Stream = myHttpWebRequest.GetRequestStream()
    newStream.Write(byte1, 0, byte1.Length)
    newStream.Close()

    Hope you can help.

    Thanks,

    Windows Form upload data file by HTTP POST
  2. #2
    Apoc's Avatar Angry Penguin
    Reputation
    1388
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/13
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    Dim web As New System.Net.WebClient()
    Dim responseHtml As String = System.Text.Encoding.ASCII.GetString(web.UploadFile("your url here", "file name here"))
    Not quite sure what all the rest of your post data stuff is for; however that's the easiest way to do a file upload.

Similar Threads

  1. [Help] Please upload your file fast ;)
    By INS4N3K1LL in forum World of Warcraft Emulator Servers
    Replies: 8
    Last Post: 05-16-2008, 12:26 PM
  2. What would be the Causes of a Slow Exucute Data file on Navicat?
    By Snailz in forum World of Warcraft Emulator Servers
    Replies: 10
    Last Post: 01-23-2008, 06:02 PM
  3. File splitting software (good for uploading big files)
    By Marlo in forum World of Warcraft Bots and Programs
    Replies: 15
    Last Post: 06-25-2007, 07:20 AM
  4. HELP! Can't find data file!!
    By Rekro in forum WoW ME Questions and Requests
    Replies: 2
    Last Post: 12-25-2006, 11:42 PM
All times are GMT -5. The time now is 04:52 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search