如何从c#调用post方法 [英] how to call post method from c#
本文介绍了如何从c#调用post方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
如何在不使用路线的情况下从c#拨打方法帖子
Dear All,
how can i call method post from c# with out using Route
[Route("post1")]
[HttpPost]
public HttpResponseMessage Post(List<Obj> _lstvalue)
{ returnControllerContext.Request.CreateResponse(HttpStatusCode.InternalServerError);
}
[Route("post2")]
[HttpPost]
public HttpResponseMessage PostList (List<Dictionary<string,string>> _ListDataDict)
{ returnControllerContext.Request.CreateResponse(HttpStatusCode.InternalServerError);
}
我的c#代码调用此方法我使用
使用(HttpClient客户端) = new HttpClient())
response = client.PostAsJsonAsync( http:// localhost:1523 / Post1 [ ^ ],SMSList).Result;
return response.Content.ReadAsAsync< string>()。结果;
i需要从URI中删除POST1和POST2
in My c# code to call this method i used
using (HttpClient client = new HttpClient())
response = client.PostAsJsonAsync("http://localhost:1523/Post1[^]", SMSList).Result;
return response.Content.ReadAsAsync<string>().Result;
i need to remove POST1 And POST2 from URI
推荐答案
使用webclient
https://msdn.microsoft.com/en-us/library/system.net.webclient(v = vs.110).aspx [ ^ ]
http://www.dotnetperls.com/webclient [ ^ ]
http://stackoverflow.com/questions/5401501/how-to-post-data-to-specific-url-using-webclient- in-c-sharp [ ^ ]
use webclient
https://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.110).aspx[^]
http://www.dotnetperls.com/webclient[^]
http://stackoverflow.com/questions/5401501/how-to-post-data-to-specific-url-using-webclient-in-c-sharp[^]
这篇关于如何从c#调用post方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文