0
我有一個會談自託管的Web API,一個簡單的客戶端應用程序:參數傳遞到WEB API自託管服務
class Program
{
static HttpClient client = new HttpClient();
static void Main(string[] args)
{
client.BaseAddress = new Uri("http://localhost:8080");
LoadForeman();
Console.WriteLine("Press Enter to quit.");
Console.ReadLine();
}
static void LoadForeman()
{
HttpResponseMessage resp = client.GetAsync("api/foreman").Result;
resp.EnsureSuccessStatusCode();
var foreman = resp.Content.ReadAsAsync<IEnumerable<SelfHost.Foreman>>().Result;
foreach (var f in foreman)
{
Console.WriteLine("{0} {1}", f.ForeBadge, f.ForeName);
}
}
}
如何傳遞參數(字符串)從客戶機到服務?
編輯:WEB API服務
static void Main(string[] args)
{
var config = new HttpSelfHostConfiguration("http://localhost:8080");
//describes how to access API via HTTP
config.Routes.MapHttpRoute(
"API Default", "api/{controller}/{id}",
new { id = RouteParameter.Optional });
using (HttpSelfHostServer server = new HttpSelfHostServer(config))
{
server.OpenAsync().Wait();
Console.WriteLine("Press Enter to quit.");
Console.ReadLine();
}
}
服務器如何指望那些字符串?請求參數?一個JSON對象?還有別的嗎? – David
這是自我託管的web api,客戶端是一個控制檯應用程序。我將在上面添加WEB API服務的主要方法。 –
我的意思是,你試圖發送的值是什麼,控制器期望如何接收這些值? – David