我怎样才能调用Web API Post方法? [英] How can I call a Web API Post method?
本文介绍了我怎样才能调用Web API Post方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要添加一个Post方法,并已经得到了这个启动:
I need to add a Post method, and have gotten this start:
private void AddDepartment()
{
// AccountId (int) and Name (string) are the two vals other than Id, which is auto-added on the server
int onAccountOfWally = 42;
string moniker = "Wild Billy Jack Black Stallion";
Cursor.Current = Cursors.WaitCursor;
try
{
string uri = String.Format("http://platypus:28642/api/Platypi/{0}/{1}", onAccountOfWally, moniker);
var webRequest = (HttpWebRequest)WebRequest.Create(uri);
webRequest.Method = "POST";
//var webResponse = (HttpWebResponse)WebResponse. <-- there is no "Create" for this...
}
finally
{
Cursor.Current = Cursors.Default;
}
}
什么我需要做派这个URI多达处理?
What do I need to do to send this uri on up to be processed?
请注意:如果这有什么差别,客户端是Windows CE / .NET 3.5的项目。我的上午的使用JSON.NET
Note: If it makes any difference, the client is a Windows CE / .NET 3.5 project. I am using JSON.NET
推荐答案
您需要调用的GetResponse()方法的请求以实际拨打电话,并接收响应:
You need to call GetResponse() method on the request to actually make the call, and receive the response:
var webResponse = (HttpWebResponse)webRequest.GetResponse();
这篇关于我怎样才能调用Web API Post方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文