2

I'm trying to use C# and the .NET Framework 4.0 to make a program which can upload a local file along with some additional request parameters through an HTTP POST request.

Basically it would result in a request like this:

http:\\example.com\upload.html?file=<filedata goes here>&private=1&type=archive

It should be a POST request though not a GET request.

Does ASP.NET 4.0 provide any means of doing this?

Edit for clarity: I want to upload a local file to a server with my program, my program will not run on the server.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Kyle V.
  • 4,752
  • 9
  • 47
  • 81
  • ASP.NET?.......http://blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web-api.aspx – Robert Harvey Jul 10 '12 at 18:50
  • OK. *Are you using ASP.NET?* The above blog entry has a detailed description and sample code, using the ASP.NET Web API. – Robert Harvey Jul 10 '12 at 18:54
  • 1
    No I am not currently using ASP.NET – Kyle V. Jul 10 '12 at 18:56
  • You're going to need something to process the POST request, so if you don't want to stand up an ASP.NET server, you will have to roll your own server of some sort. Node.JS comes to mind. Have a look here: http://ayende.com/blog/72705/node-cs and https://github.com/Rduerden/Node.cs – Robert Harvey Jul 10 '12 at 19:00
  • Are you trying to upload a file to an existing server or do you need to create a server app that allows users to upload a local file? – Josh Jul 10 '12 at 19:01
  • @Josh I want to upload to an existing server that I don't own. – Kyle V. Jul 10 '12 at 19:06
  • 1
    Easy enough. The answer by Stephen below is all you need. – Josh Jul 10 '12 at 19:14

1 Answers1

5

Yes, you can use the System.Net.HttpWebRequest class. Set the Method property to "POST" to use POST rather than GET. This question seems to have it covered.

Community
  • 1
  • 1
Stephen Hewlett
  • 2,415
  • 1
  • 18
  • 31