C# .NET Uploading file to a web form using HttpWebRequest

前端 未结 1 327
庸人自扰
庸人自扰 2021-01-14 23:31

Does anyone have a working example using HttpWebRequest in C# to submit a file from the local drive to a multipart/form-data web form?

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-15 00:04

    it is WAY easier to do this with WebClient

    string url = "http://myserver/myapp/upload.aspx";
    string file = "c:\\files\\test.jpg";
    WebClient wc = new WebClient();
    wc.UploadFile(url,"post",file);
    

    If it needs to be httpwebrequest I can put something together for you (it is possible), but it will be more like 50 lines then 5

    0 讨论(0)
提交回复
热议问题