POST方法:http://localhost:15423/api/控制器名称
GET方法:http://localhost:15423/api/控制器名称?参数名称=1&.............
/// <summary>
/// 测试方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btn_Click(object sender, EventArgs e)
{
var httpRequst = new StringContent("http://localhost:8888/api/Test?UserID=1");//请求Get方法,Controller/id 或者 Controller?id=id会路由到 Get(int id)
httpRequst.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
var httpClient = new HttpClient();
var ResponseJson = httpClient.PostAsync("{UserID:1}", httpRequst).Result.Content.ReadAsStringAsync().Result;
this.txt_Result.InnerText = ResponseJson;
}
.NET MVC 4.0 Web API 测试接口,对应的路由,布布扣,bubuko.com
.NET MVC 4.0 Web API 测试接口,对应的路由