Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. HttpWebRequest

HttpWebRequest

Scheduled Pinned Locked Moved C#
tutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Moon Boy
    wrote on last edited by
    #1

    Hi, How can i send a FILE with HttpWebRequest I opened a StreamWriter with GetRequestStream() But i have no ideia how to send a file :\ because in the page have a FileField ;\ Thanks.

    H 1 Reply Last reply
    0
    • M Moon Boy

      Hi, How can i send a FILE with HttpWebRequest I opened a StreamWriter with GetRequestStream() But i have no ideia how to send a file :\ because in the page have a FileField ;\ Thanks.

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Take a look at RFC 1867[^] which describes file uploads using HTTP. For example, if you only need to upload a single plain text file, you cn set the HttpWebRequest.ContentType to "multipart/form-data; boundary=ABC123". You then get the request stream using HttpWebRequest.GetRequestStream and, to make things easier, pass that to a StreamWriter with whatever Encoding is appropriate (should be the same as the file encoding you're uploading, though multiple parts can have different encodings that would go into the "Content-type" header as "charset". You would write to the request stream writer like so:

      --ABC123
      Content-type: application/x-www-form-urlencoded
       
      param1=value1&param2=value2
      --ABC123
      Content-disposition: form-data; name="FileField"
      Content-type: text/plain
       
      This content is from a text document.
      --ABC123--

      Notice the intentional line breaks and how the last line ends with -- (the end of the MIME boundary). Learning this is crucial to understanding how to HTTP and MIME works, and the RFC is actually quite easy to read (compared to many others I've read).

      Microsoft MVP, Visual C# My Articles

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups