Post fields and a file using the new System.Net.WebClient

流过昼夜 提交于 2019-12-06 15:38:14

I think you need this:

http://dzimchuk.net/post/uploading-a-file-over-http-in-net

This is a very well written blog. See the last example.

There are a lot of examples if you do a fast google search, anyway, here goes some samples:

Simple GET

WebClient webClient = new WebClient();
webClient.Headers["Accept"] = "application/json"; //setting headers

string json = webClient.DownloadString(url);

Simple POST

NameValueCollection values = new NameValueCollection();
values["user"] = username;
values["pwd"] = password;
webClient.UploadValues(url, values);

There's also an UploadData that sends byte arrays and UploadFile that allows you to upload files directly from disk.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!