Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 红隼:调用WebRequest&x27;URL在浏览器中工作时不工作? 更新:_Asp.net_Visual Studio_Powershell_Asp.net Core_Kestrel Http Server - Fatal编程技术网

Asp.net 红隼:调用WebRequest&x27;URL在浏览器中工作时不工作? 更新:

Asp.net 红隼:调用WebRequest&x27;URL在浏览器中工作时不工作? 更新:,asp.net,visual-studio,powershell,asp.net-core,kestrel-http-server,Asp.net,Visual Studio,Powershell,Asp.net Core,Kestrel Http Server,以下错误仅在使用Kestrel启动应用程序时发生 我已经为Microsoft.AspNetCore.Authentication.Negotiate添加了以下两行代码 // in public void ConfigureServices(IServiceCollection services) services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate(); // in public void

以下错误仅在使用Kestrel启动应用程序时发生

我已经为Microsoft.AspNetCore.Authentication.Negotiate添加了以下两行代码

// in public void ConfigureServices(IServiceCollection services)
services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();

// in public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseAuthentication();

我使用Visual Studio 2019创建了一个新的测试Asp.Net核心Web API项目(使用Windows身份验证)。然后在VisualStudio中运行它,会弹出一个浏览器,其中显示json返回

然后我打开一个Powershell窗口并测试url。它有以下错误

PS C:\> Invoke-WebRequest https://localhost:5001/weatherforecast
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At line:1 char:1
+ Invoke-WebRequest https://localhost:5001/weatherforecast
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
我找到了
ASP.NET核心HTTPS开发证书

PS C:\> ls Cert:\CurrentUser\My | ? Subject -eq 'CN=localhost' | fl

Subject      : CN=localhost
Issuer       : CN=localhost
Thumbprint   : 7A16573FF2DBA47695B8CA15916D445C9361F255
FriendlyName : ASP.NET Core HTTPS development certificate
NotBefore    : 12/6/2019 4:45:04 PM
NotAfter     : 12/5/2020 4:45:04 PM
Extensions   : {System.Security.Cryptography.Oid, System.Security.Cryptography.Oid, System.Security.Cryptography.Oid,
               System.Security.Cryptography.Oid...}
它还是有错误吗

PS C:\> Invoke-WebRequest https://localhost:5001/weatherforecast -CertificateThumbprint 7A16573FF2DBA47695B8CA15916D445C -UseDefaultCredentials
9361F255
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At line:1 char:1
+ Invoke-WebRequest https://localhost:5001/weatherforecast -Certificate ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

这个对我有用。我可以从web api中读取它。 使用参数为-Certificate$cert的Invoke RestMethod进行尝试

$cert = Get-ChildItem -Path Cert:\CurrentUser\My\4E1E5F6B5BAD49B13521C2DF12275C37E126DBB9
$response = Invoke-RestMethod https://localhost:5001/weatherforecast -Certificate $cert
Write-Host $response.Count

应该是http还是https?这可能只是隐藏了一个证书验证错误。我已经用cert参数更新了这个问题。你能试试
调用rest方法吗https://localhost:5001/weatherforecast -CertificateThumbprint 7A16573FF2DBA47695B8CA15916D445C9361F255,
Invoke RestMethod
得到了相同的错误。我仍然通过使用
-certificate
得到了相同的错误。我刚刚在VisualStudio中运行了新创建的项目https://localhost:44334/weatherforecast -证书$cert-UseDefaultCredentials
在我使用IIS Express更改visual studio后生效。(Kestrel收到错误)