前些天,Insus.NET有演示Web API接口的操作:
《http://www.cnblogs.com/insus/p/5670401.html

《http://www.cnblogs.com/insus/p/5673641.html

但是,有网友说,不想使用jQuery,全部以ASP.NET MVC来实现。Ok,那来看看,先来实现POST的功能,即是往Web API添加数据。

在控制器中,创建两个Action,即是视图Action,另一个是POST的Action:
不使用jQuery对Web API接口POST,PUT,DELETE数据

HttpClient client = new HttpClient();

            HttpContent httpcontent = new StringContent(size.ToJson(), System.Text.Encoding.UTF8, "application/json");

            client.PostAsync("http://localhost:9001/api/size", httpcontent)
                .ContinueWith((postTask) =>
                {
                    postTask.Result.EnsureSuccessStatusCode();
                });
Source Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-01
  • 2021-08-05
  • 2022-12-23
  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2022-12-23
  • 2021-10-07
  • 2021-06-13
相关资源
相似解决方案