Advertisement
Advertisement

新足迹

 找回密码
 注册
新足迹 › 门户 › AI 相关› 查看内容

C#CLIENT 端当 做GET 的时候怎么传用户名密码到ASP.NET WEBAPI

2013-4-9 21:03| 发布者: yangwulong1978 | 查看: 1788| 原文链接



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 我还不知道怎么传。
Advertisement
Advertisement


Advertisement
Advertisement
返回顶部