如何使用Angular HTTP Post Call通过NTLM凭据?

发布于 2025-01-28 01:28:28 字数 559 浏览 3 评论 0原文

我正在Localhost工作,那里使用2个不同端口的Angular和Web API现在引起了问题。

我试图从Angular上调用Web api c#

  this.http.post< accessToken>(`$ {$ {this.url}/api/home/home/eid/?code = 12345sfffs`,{headers:this.htttpheaders})
       。
         console.log(“ hi”);
         console.log(响应);
        返回响应;
        }); ````````
 

但是我要低于错误,

无法加载资源:

当我尝试在Postman中尝试时,该服务器以401的状态(未经授权)响应,我也遇到了相同的401错误,后来我通过在Postman中添加NTLM凭据来修复以获取200响应。

但是如何通过Angular Post Call传递NTLM凭据? 为什么Web API期望NTLM凭据?

提前致谢!

I am working on localhost where angular and web api using 2 different ports that's causing issue now.

I am trying to call web api c# from angular like this

this.http.post<AccessToken>(`${this.url}/api/Home/Eid/?code=12345sfffs`,{headers:this.httpHeaders})
       .pipe(Response => {
         console.log("hi");
         console.log(Response);
        return Response;
        }); ```

But I am getting below error

Failed to load resource: the server responded with a status of 401 (Unauthorized)

When I tried in postman also I got same 401 error and later I fixed by adding NTLM credentials in postman to get 200 response.

But how to pass NTLM credentials from angular post call?
And why web api expecting for NTLM credentials?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伤感在游骋 2025-02-04 01:28:28

我已经在Web API中修改了我的Angular帖子呼叫

  return
 this.http.post<AccessToken>(`${this.url}/api/Home/Eid/?code=12345sfffs`,{headers:this.httpHeaders},{
withCredentials: true })
        .pipe(Response => {
         console.log("hi");
         console.log(Response);
         return Response;
         });

,我对此进行了修改。

<httpProtocol>
      <customHeaders>       
        <add name="Access-Control-Allow-Origin" value="http://localhost:4200"/>               
        <add name="Access-Control-Allow-Credentials" value="true" />              
      </customHeaders>
    </httpProtocol>

I have modified my angular post call to this

  return
 this.http.post<AccessToken>(`${this.url}/api/Home/Eid/?code=12345sfffs`,{headers:this.httpHeaders},{
withCredentials: true })
        .pipe(Response => {
         console.log("hi");
         console.log(Response);
         return Response;
         });

In Web API, I have modified web.config to this

<httpProtocol>
      <customHeaders>       
        <add name="Access-Control-Allow-Origin" value="http://localhost:4200"/>               
        <add name="Access-Control-Allow-Credentials" value="true" />              
      </customHeaders>
    </httpProtocol>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文