我正在尝试在 C# 代码中读取 Web 资源。不幸的是,该代码仅在从本地驱动器运行时有效,并且在从网络共享运行时抛出异常(这就是我需要的)。
The underlying connection was closed: Unable to connect to the remote server.
in System.Net.HttpWebRequest.GetResponse()
.........
Caused by:
An invalid argument was supplied
in System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
in System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
in System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
in System.Net.Connection.CompleteStartConnection(Boolean async, HttpWebRequest httpWebRequest)
我尝试过类似于(这会引发异常)的代码:
request = (HttpWebRequest)WebRequest.Create(url);
以及根据http://msdn.microsoft.com/en-us/library/2b86d684的直接套接字连接。
我怀疑 Windows 中有某种安全设置会阻止网络连接。有可能解决这个问题吗?通过广告策略?或者我的代码中有什么东西?