Web Api Call导致401 Unauthorized访问

时间:2014-03-31 13:17:14

标签: asp.net-web-api

我目前正在通过服务器端代码进行webapi调用

        var client = new HttpClient(new HttpClientHandler() {UseDefaultCredentials = true});

        client.BaseAddress = new Uri(apiurl);
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

我是否需要在客户端标头中包含更多信息才能使呼叫通过?这可能不是回答这个问题的足够信息,但在这种情况下我不知道我不知道的是什么,我不确定该问题还包括哪些其他信息。 webapi和Web应用程序托管在同一个IIS服务器实例上,因此调用的来源将来自同一个根URL。我已经在webapi中启用了CORS,并且只是将params设置为星号以包含所有URL,但是仍然没有效果。任何帮助,将不胜感激。

附加信息:这是响应中返回的标头的值。看起来它正在使用NTLM身份验证。

从我的本地GUI调用远程webapi

IS AUTH: True Username: xxx\xxxxxxxxx
AUTH TYPE: Negotiate
ApiURL: http://testserver1/bbwebapi/api/v1/bbapi/
OK
Pragma:no-cache
Persistent-Auth:true
Cache-Control:no-cache
Date:Mon, 31 Mar 2014 19:42:12 GMT
Server:Microsoft-IIS/7.5
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET

调用远程webapi的远程服务器上的相同GUI代码顺便说一下,它们是相同的服务器,这些是标题

IS AUTH: True Username: xxx\xxxxx
AUTH TYPE: Negotiate
ApiURL: http://testserver1/bbwebapi/api/v1/bbapi/
Unauthorized
Cache-Control:private
Server:Microsoft-IIS/7.5
WWW-Authenticate:Negotiate
X-Powered-By:ASP.NET
Date:Mon, 31 Mar 2014 19:44:30 GMT

IS AUTH,USERNAME和AUTHTYPE分别来自HttpContext.User.Identity.IsAuthenticated,HttpContext.User.Identity.Name和HttpContext.User.Identity.AuthenticationType

0 个答案:

没有答案