如何在我的winform中调用webapi方法

时间:2016-09-29 08:08:07

标签: c# asp.net-web-api

我有我自己的休息API我在c#3.5 framewok中调用下面的代码,但这种方法不打电话请帮助我

 var json = JsonConvert.SerializeObject(objproperties);
                string url = "http://localhost:3423";
                using (WebClient client = new WebClient())
                {
                    responseData = client.UploadString(url+"api/json/Cardpayment", json);
                }  

我的REST API方法。

    [System.Web.Http.AcceptVerbs("GET", "POST")]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public HttpResponseMessage Cardpayment(classProperties objproperties)
    {
        try
        {
                    string myid = objproperties.myid;
        }
    }

1 个答案:

答案 0 :(得分:0)

添加Header ..对我来说很好..

            client.Headers.Add("API-Version: 5.0");
            client.Headers.Add("Content-Type", "application/json");
      responseData = client.UploadString(url+"api/json/Cardpayment", json);