我需要添加一个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
答案 0 :(得分:3)
您需要在请求上调用GetResponse()方法来实际进行调用,并收到响应:
var webResponse = (HttpWebResponse)webRequest.GetResponse();