我能使用.NET的HttpClient访问Azure移动服务吗?
如何使用HttpClient与Mobile Service的内置自定义身份验证/授权模式进行身份验证?
由于没有传递任何身份验证凭据,此操作始终返回401:
var client = new HttpClient();
var response = client.GetAsync("http://localhost:49190/api/test").Result;
此外,我使用移动服务客户端时,为什么我的应用程序密钥、主密钥或用户授权密钥总是返回(401)未经授权的状态呢?请参考Mobile Service Client。
客户端:
var mobileClient = new MobileServiceClient("http://localhost:49190/", "[my key]");
var response = mobileClient.InvokeApiAsync("test").Result;
服务器端:
[AuthorizeLevel(AuthorizationLevel.Application)]
public class TestController : ApiController
{
public ApiServices Services { get; set; }
// GET api/Test
public string Get()
{
Services.Log.Info("Hello from custom controller!");
return "Hello";
}
}