簡體   English   中英

如何調用Web API Post方法?

[英]How can I call a Web API Post method?

我需要添加一個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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM