James Jeffery
James Jeffery

Reputation: 12579

Sending a File Along HTTP?

Just wondering how I would send a file along HTTP. I'm using HTTPRequest. The data needs to be outputted in its binary form so I can send it in a multipart request. And ideas on how I do it? I'm totally lost.

Upvotes: 3

Views: 150

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062715

If you just want the file sent as the body of a POST / STOR / etc, then WebClient makes this easy:

    using (WebClient client = new WebClient())
    {
        client.UploadFile(address, fileName);

        // or to specify a custom method:
        client.UploadFile(address, "PUT", fileName);
    }

If you need a form it is trickier; you'll need multipart-mime, which isn't supported directly; you'll have to write it or use existing code from the net.

Upvotes: 3

Related Questions