一、好比有一服務web
[HttpPost] public ActionResult Index(string str) { try { System.IO.File.WriteAllText(Server.MapPath(@"/test/txt.txt"), str, Encoding.UTF8); return Content("已上傳完成 "); } catch (Exception ex) { return Content(ex.Message); throw; } }
二、使用webclient發出請求app
static void Main(string[] args) { WebClient wc = new WebClient(); wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); var b = Encoding.UTF8.GetBytes("str=我是從webclient來的朋友"); var res = wc.UploadData(@"http://localhost:1863/", "post", b); var result = Encoding.UTF8.GetString(res); Console.WriteLine(result); Console.Read(); }