如何调用Web API Post方法
本文关键字:Web API Post 方法 调用 何调用 | 更新日期: 2024-10-21 03:07:55
我需要添加一个Post方法,并且已经开始了:
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发送到上进行处理?
注意:如果有任何不同,则客户端是Windows CE/。NET 3.5项目。我正在使用JSON。NET
您需要对请求调用GetResponse()方法才能真正进行调用,并接收响应:
var webResponse = (HttpWebResponse)webRequest.GetResponse();