使用c#和webrequest提交multipart / form-data POST

时间:2016-10-13 17:01:04

标签: c# forms multipartform-data webrequest

嘿我正在尝试提交multipart / form-data请求。

        string sURL = base_url + "?action=add-torrent";
        WebRequest torrent_post = WebRequest.Create(sURL);
        torrent_post.ContentType = "multipart/form-data";
        torrent_post.Method = "POST";
        var reqparm = new System.Collections.Specialized.NameValueCollection();
        byte[] bytes = System.IO.File.ReadAllBytes("one.torrent");
        Debug.WriteLine(bytes[5]);
        using (Stream requestStream = torrent_post.GetRequestStream())
        {
            requestStream.Write(bytes, 0, bytes.Length);
            requestStream.Close();
        }
我试图发送数据的api是:

http://[iP]:[PORT]/gui/?action=add-file

This action is different from the other actions in that it uses HTTP POST instead of HTTP GET to submit data to µTorrent. The HTTP form must use an enctype of "multipart/form-data" and have an input field of type "file" with name "torrent_file" that stores the local path to the file to upload to µTorrent.

基于此,我唯一缺少的是实际的输入字段。如何实现它?谢谢

0 个答案:

没有答案