|
1. for example I have a asp.net webapi : http://localhost/api/product. 2. I have a C# client to consume this webapi. something like that to get whole list of product. // List all products. HttpResponseMessage response = client.GetAsync("api/products").Result; // Blocking call! if (response.IsSuccessStatusCode) { // Parse the response body. Blocking! var products = response.Content.ReadAsAsync<IEnumerable<Product>>().Result; foreach (var p in products) { Console.WriteLine("{0}\t{1};\t{2}", p.Name, p.Price, p.Category); } } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } 我的问题是怎么从C#client 端传用户名,密码到WEB API 里去。 我想的是当C#CLIENT去 SERVER 的WEBAPI拿整个PRODUCTLIST前,先传用户名,密码过去,SERVER的WEB API验证,,如果是授权的用户,就让GET 如果不是,就不让GET 。。 POST 我会传用户名,密码过去,GET 我还不知道怎么传。 |