无法从 windows 服务器访问网络

Can't reach the web from windows server

我正在尝试在客户端服务器上获取程序 运行,我需要做的一件事是执行网络请求以发送电子邮件通知。

在本地一切正常,但在客户端服务器上不行,我不明白为什么。

这是例外情况(Exception.GetType().Name: AggregateException):

Exception: One or more errors occurred. (An invalid argument was supplied. (www.gstatic.com:80)) at Microsoft.FSharp.Control.AsyncResult`1.Commit() in D:\a\_work\s\src\fsharp\FSharp.Core\async.fs:line 391
at Microsoft.FSharp.Control.AsyncPrimitives.QueueAsyncAndWaitForResultSynchronously[a](CancellationToken token, FSharpAsync`1 computation, FSharpOption`1 timeout) in D:\a\_work\s\src\fsharp\FSharp.Core\async.fs:line 1042
at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronously[T](CancellationToken cancellationToken, FSharpAsync`1 computation, FSharpOption`1 timeout) in D:\a\_work\s\src\fsharp\FSharp.Core\async.fs:line 1070
at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken) in D:\a\_work\s\src\fsharp\FSharp.Core\async.fs:line 1365
at Program.checkForInternetConnection(FSharpFunc`2 log)

内部异常(递归遍历内部异常时没有附加信息):

InnerException: System.Net.Http.HttpRequestException: An invalid argument was supplied. (www.gstatic.com:80)
---> System.Net.Sockets.SocketException (10022): An invalid argument was supplied.
at System.Net.Sockets.Socket..ctor(AddressFamily , SocketType , ProtocolType )
at System.Net.Sockets.Socket..ctor(SocketType , ProtocolType )
at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String , Int32 , HttpRequestMessage , Boolean , CancellationToken )
--- End of inner exception stack trace ---
at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String , Int32 , HttpRequestMessage , Boolean , CancellationToken )
at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage , Boolean , CancellationToken )
at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage , Boolean , CancellationToken )
at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(HttpRequestMessage )
at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken )
at System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(HttpRequestMessage , Boolean , CancellationToken )
at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage , Boolean , Boolean , CancellationToken )
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage , Boolean , CancellationToken )
at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage , HttpCompletionOption , CancellationTokenSource , Boolean , CancellationTokenSource , CancellationToken )

这是有问题的代码

type Async with
    static member Await task =
        task |> Async.AwaitTask |> Async.RunSynchronously
    
let client = new HttpClient()
    
let checkForInternetConnection log =
    let url = "http://www.gstatic.com/generate_204"
    try
        let response = client.GetAsync(url) |> Async.Await
        let status = response.StatusCode
        log $"Has internet connection, could reach {url}. Expecting status code NoContent, was: {status.ToString()}."
        true
    with
        | :? Exception as e -> 
            log $"Exception: {e.Message} {e.StackTrace}"
            false

当我们 运行 它在本地服务器上而不是在文件服务器上时,我工作了。

我也是 .net 版本,并且得到了这个,所以我猜是 .net 3:

PS C:\Users0000tova-adm> Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -Name version -EA 0 | Where { $_.PSChildName -Match '^(?!S)\p{L}'} | Select PSChildName, version

PSChildName Version
----------- -------
v2.0.50727 2.0.50727.4927
v3.0 3.0.30729.4926
Windows Communication Foundation 3.0.4506.4926
Windows Presentation Foundation 3.0.6920.4902
v3.5 3.5.30729.4926
Client 4.7.03190
Full 4.7.03190

Google 什么也没给我,我完全卡住了

我无法解决这个问题,但最终我们通过 运行 从不同的位置让它工作。