我正在尝试从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中存在某种安全设置,阻止网络连接。有可能通过AD策略或代码中的某些设置来解决吗?
url
抛出了什么异常?同样的 URL 在本地运行时是否也会导致应用程序抛出异常? - Oded