本文整理汇总了C#中System.Net.WebException.WebException构造函数的典型用法代码示例。如果您正苦于以下问题:C# WebException构造函数的具体用法?C# WebException怎么用?C# WebException使用的例子?那么恭喜您, 这里精选的构造函数代码示例或许可以为您提供帮助。
在下文中一共展示了WebException构造函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Socket
try
{
// A 'Socket' object has been created.
Socket httpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// The IPaddress of the unknown uri is resolved using the 'Dns.Resolve' method.
IPHostEntry hostEntry = Dns.Resolve("http://www.contoso.com");
IPAddress serverAddress = hostEntry.AddressList[0];
IPEndPoint endPoint = new IPEndPoint(serverAddress, 80);
httpSocket.Connect(endPoint);
Console.WriteLine("Connection created successfully");
httpSocket.Close();
}
catch(SocketException e)
{
String exp = e.Message;
// Throw the WebException with no parameters.
throw new WebException();
}
开发者ID:.NET开发者,项目名称:System.Net,代码行数:21,代码来源:WebException
示例2: Socket
try
{
// A 'Socket' object has been created.
Socket httpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// The IPaddress of the unknown uri is resolved using the 'Dns.Resolve' method.
IPHostEntry hostEntry = Dns.Resolve(connectUri);
IPAddress serverAddress = hostEntry.AddressList[0];
IPEndPoint endPoint = new IPEndPoint(serverAddress, 80);
httpSocket.Connect(endPoint);
Console.WriteLine("Connection created successfully");
httpSocket.Close();
}
catch(SocketException e)
{
Console.WriteLine("\nException thrown.\nThe Original Message is: "+e.Message);
// Throw the 'WebException' object with a message string specific to the situation.
throw new WebException("Unable to locate the Server with 'www.contoso.com' Uri.");
}
开发者ID:.NET开发者,项目名称:System.Net,代码行数:20,代码来源:WebException
示例3: Socket
try
{
// A 'Socket' object has been created.
Socket httpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// The IPaddress of the unknown uri is resolved using the 'Dns.Resolve' method.
IPHostEntry hostEntry = Dns.Resolve("http://www.contoso.com");
IPAddress serverAddress = hostEntry.AddressList[0];
IPEndPoint endPoint = new IPEndPoint(serverAddress, 80);
httpSocket.Connect(endPoint);
Console.WriteLine("Connection created successfully");
httpSocket.Close();
}
catch(SocketException e)
{
Console.WriteLine("\nException thrown.\nThe Original Message is: "+e.Message);
// Throw the 'WebException' object with a message string and message status specific to the situation.
throw new WebException("Unable to locate the Server with 'www.contoso.com' Uri.",WebExceptionStatus.NameResolutionFailure);
}
开发者ID:.NET开发者,项目名称:System.Net,代码行数:21,代码来源:WebException
示例4: Socket
try
{
// A 'Socket' object has been created.
Socket httpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// The IPaddress of the unknown uri is resolved using the 'Dns.Resolve' method.
IPHostEntry hostEntry = Dns.Resolve(connectUri);
IPAddress serverAddress = hostEntry.AddressList[0];
IPEndPoint endPoint = new IPEndPoint(serverAddress, 80);
httpSocket.Connect(endPoint);
Console.WriteLine("Connection created successfully");
httpSocket.Close();
}
catch(SocketException e)
{
Console.WriteLine("\nException thrown.\nThe Original Message is: "+e.Message);
// Throw the 'WebException' object with a message string specific to the situation;
// and the 'InnerException' which actually lead to this exception.
throw new WebException("Unable to locate the Server with 'www.contoso.com' Uri.",e);
}
开发者ID:.NET开发者,项目名称:System.Net,代码行数:22,代码来源:WebException
示例5: IPEndPoint
// Send the data.
Encoding ASCII = Encoding.ASCII;
string requestPage = "GET /nhjj.htm HTTP/1.1\r\nHost: " + connectUri + "\r\nConnection: Close\r\n\r\n";
Byte[] byteGet = ASCII.GetBytes(requestPage);
Byte[] recvBytes = new Byte[256];
// Create an 'IPEndPoint' object.
IPHostEntry hostEntry = Dns.Resolve(connectUri);
IPAddress serverAddress = hostEntry.AddressList[0];
IPEndPoint endPoint = new IPEndPoint(serverAddress, 80);
// Create a 'Socket' object for sending data.
Socket connectSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream,ProtocolType.Tcp);
// Connect to host using 'IPEndPoint' object.
connectSocket.Connect(endPoint);
// Sent the 'requestPage' text to the host.
connectSocket.Send(byteGet, byteGet.Length, 0);
// Receive the information sent by the server.
Int32 bytesReceived = connectSocket.Receive(recvBytes, recvBytes.Length, 0);
String headerString = ASCII.GetString(recvBytes, 0, bytesReceived);
// Check whether 'status 404' is there or not in the information sent by server.
if(headerString.IndexOf("404")!=-1)
{
bytesReceived = connectSocket.Receive(recvBytes, recvBytes.Length, 0);
MemoryStream memoryStream = new MemoryStream(recvBytes);
getStream = (Stream) memoryStream;
// Create a 'WebResponse' object
WebResponse myWebResponse = (WebResponse) new HttpConnect(getStream);
Exception myException = new Exception("File Not found");
// Throw the 'WebException' object with a message string, message status,InnerException and WebResponse
throw new WebException("The Requested page is not found.",myException,WebExceptionStatus.ProtocolError,myWebResponse);
}
connectSocket.Close();
开发者ID:.NET开发者,项目名称:System.Net,代码行数:42,代码来源:WebException
注:本文中的System.Net.WebException.WebException构造函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论