简体   繁体   English

Asp.NET Core中的C#AllowAutoRedirect等效项

[英]c# AllowAutoRedirect equivalent in Asp.NET Core

I was wondering something while writing a HTTPWebRequest in ASP.Net Core. 我在用ASP.Net Core编写HTTPWebRequest时想知道什么。 I do my request correctly and when I have to do set headers for it, before ASP.Net core I was able to do : 我正确地执行了我的请求,并且当我必须为它设置标题时,在ASP.Net core之前我可以做到:

requestPOST.Method = "POST";
requestPOST.UseDefaultCredentials = false;
requestPOST.AllowAutoRedirect = false; 

But now I can't, AllowAutoRedirect dosen't exist it seems, so does the problem come from me and my packages or does AllowAutoRedirect dosen't exist anymore and is there a way to don't allow redirection in another way ? 但是现在我不知道了,AllowAutoRedirect似乎不存在,那么问题出在我和我的软件包中吗,还是AllowAutoRedirect不再存在了,有没有办法不允许其他方式的重定向?

Thanks. 谢谢。

You can use ConfigurePrimaryHttpMessageHandler when AddHttpClient, like: 您可以在AddHttpClient时使用ConfigurePrimaryHttpMessageHandler ,例如:

services.AddHttpClient()
   .ConfigurePrimaryHttpMessageHandler(() =>
   {
        return new HttpClientHandler
        {
            AllowAutoRedirect = false
        };
   });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM