views:

48

answers:

1

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.

+3  A: 

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.

Marc Gravell