Questions tagged [webexception]
81 questions
174
votes
6 answers
System.Net.WebException HTTP status code
Is there an easy way to get the HTTP status code from a System.Net.WebException?

Gilsham
- 2,276
- 2
- 13
- 14
121
votes
4 answers
WebException how to get whole response with a body?
In WebException I cannot see body of GetResponse. This is my code in C#:
try {
return GetResponse(url + "." + ext.ToString(), method, headers, bodyParams);
} catch (WebException ex) {
switch (ex.Status) {
case…

iwtu
- 1,519
- 3
- 12
- 12
23
votes
3 answers
HttpRequestException vs WebException
This is a general question that I'm confused about. I thought once a REST request was made, an error would come back via a WebException. In one case I have I'm getting a HttpRequestException, which doesn't allow me to get the HTTP status code.
I'm…

user3063281
- 299
- 1
- 3
- 6
18
votes
1 answer
Handling two WebException's properly
I am trying to handle two different WebException's properly.
Basically they are handled after calling WebClient.DownloadFile(string address, string fileName)
AFAIK, so far there are two I have to handle, both WebException's:
The remote name could…

baron
- 11,011
- 20
- 54
- 88
17
votes
3 answers
Get Error number in WebException Error
How To Get Error number in WebException Error?
try
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("site");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream =…

Ali Yousefi
- 2,355
- 2
- 32
- 47
17
votes
4 answers
The underlying connection was closed: An unexpected error occurred on a receive
I'm here because I have a problem while downloading some files through ftp protocol. It's weird because it occurs occasionally and even for the same single file.
Just a precision: I'm downloading very large files (from 500 Mo to 30Go)
Here are the…

Hariboox
- 171
- 1
- 1
- 4
14
votes
6 answers
WebException Could not establish trust relationship for the SSL/TLS secure channel
My company has developed a .NET web service and a client dll that uses that web service. The webservice is hosted on our server over ssl and the cert is provided and signed by GoDaddy. We have some clients in a hosted environment that are getting…

Joshua Belden
- 10,273
- 8
- 40
- 56
10
votes
1 answer
System.UriFormatException: Invalid URI: The hostname could not be parsed
All of a sudden I'm getting the following error on my website. It doesn't access a database. It's just a simple website using .NET 2.0.
I did recently apply the available windows server 2003 service packs. Could that have changed things?
I should…

Shane
- 101
- 1
- 1
- 3
8
votes
2 answers
How can I read the response from a web request when the Status is not 200?
I am having difficulty getting the response text from a HTTP web request in vb.net when I get a web exception.
This is the code I am doing it with.
Try
myWebResponse = CType(request.GetResponse(), HttpWebResponse)
…

Ruairi O'Brien
- 1,209
- 5
- 18
- 33
8
votes
2 answers
Should WebException.Response.GetResponseStream() be close / disposed?
When I catch a .NET WebException, should I close / dispose the Response.GetResponseStream()?
The MSDN example does not close or dispose anything in the exception.
Many SO answers recommend disposing the response and / or the stream.
I disposed the…

Peter
- 3,322
- 3
- 27
- 41
7
votes
1 answer
Is there a way to change HttpWebRequest behavior on 400/500 status codes?
I am working on building a fluent REST client interface on top of the HttpWebRequest/HttpWebResponse types in .NET. So far, so good...however I am trying to develop a pluggable security framework that can automatically handle security token…

jrista
- 32,447
- 15
- 90
- 130
6
votes
4 answers
Problem SSL Certificate C#
In my C# application, I got to call web services via https and validate using a .crt file that I already have. Here is the correct solution for such needs. I have updated this post once I got a working solution, thinking it might help others like…

Tvd
- 4,463
- 18
- 79
- 125
5
votes
1 answer
HttpWebRequest results in "The request was aborted: Could not create SSL/TLS secure channel"
We've introduced a few .NET pages into a Classic ASP application. When a user hits one of the .NET pages we use an HttpWebRequest to get session variable values from the ASP side by sending the request to a Class ASP page with the name of the…

Craig W.
- 17,838
- 6
- 49
- 82
5
votes
3 answers
C# how create WebException with Response status code
I make some fake class, that should have same behavior as original one.
Original class sometimes throws WebExceptions (with StatusCode in response from server).
I want repeat this behavior without any connection.
So, how can i create new…

murzagurskiy
- 1,273
- 1
- 20
- 44
4
votes
1 answer
How to Capture the Web Exception in windows phone 8?
I am using the Wamp Server for back end and C# for front end. For Cheeking purpose i turn off the server. And run the program. It throw the following error in output window.
'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight…

selvam
- 1,177
- 4
- 18
- 40