gpt4 book ai didi

c# - Web异常: Unable to connect to the remote server

转载 作者:行者123 更新时间:2023-12-02 03:43:41 28 4
gpt4 key购买 nike

我有一个客户端应用程序,它使用 WebHttpRequest 从外部服务器获取响应,它工作正常,但有时我会遇到以下异常......

System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond xx.xx.xxx.xxx:xxx at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) --- End of inner exception stack trace ---

at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)

at System.Net.HttpWebRequest.GetRequestStream()

...有什么帮助吗?

最佳答案

这更像是“请求超时”错误。您尝试连接的服务器未响应您的请求。您应该使用 try-catch 处理此异常,并在 catch block 中再次尝试连接 n 次。

关于c# - Web异常: Unable to connect to the remote server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4001113/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com