webexception

How to catch ODataErrorException when I am making an OData call through HttpWebRequest in C#?

心已入冬 提交于 2020-01-16 15:57:07
问题 I am trying to call an OData service from my .Net console application using c#. I am using HttpWebRequest to make the call. Now if there is an OData specific error, for example, an invalid JSON payload, then an ODataErrorException is thrown from the OData server. My question is how to catch that ODataErrorException and extract the proper message out of it? The exception gets caught in WebException catch block, and it only shows me "400 Bad Request". But it doesn't show me the actual error

HttpWebRequest results in “The request was aborted: Could not create SSL/TLS secure channel”

↘锁芯ラ 提交于 2020-01-10 05:01:05
问题 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 session variable we want. This approach works, except in the following situation. On our production servers our IT folks have disabled the weak cipher algorithms with some registry hacking. We want to force 128 over 128 (or so I'm told by people who know

Problem with Httpwebrequest (503)

夙愿已清 提交于 2019-12-24 15:23:56
问题 I am using HttpWebrequest to GET the result from google.I use proxies to get the data.now there is a strange problem that for some queries it return the data and for some it throws the exception The remote server returned an error: (503) Server Unavailable. . One might think that proxy is bad but when you put it in internet explorer then you open google it is there.no 503 error then.but httpwebrequest gives it on certain query.i.e if you intend to get http://www.google.com/search?q=site:http:

Get Error number in WebException Error

眉间皱痕 提交于 2019-12-21 07:29:33
问题 How To Get Error number in WebException Error? try { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("site"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); int i = stream.ReadByte(); } catch (WebException e) { //How To Get Error number in WebException Error? } 回答1: You'll want to run a test to make sure that it was a ProtocolError : if (e.Status == WebExceptionStatus.ProtocolError) { Console.WriteLine("Status

WebException how to get whole response with a body?

巧了我就是萌 提交于 2019-12-17 03:02:32
问题 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 WebExceptionStatus.ConnectFailure: throw new ConnectionException(); case WebExceptionStatus.Timeout: throw new RequestTimeRanOutException(); case WebExceptionStatus.NameResolutionFailure: throw new ConnectionException(); case WebExceptionStatus.ProtocolError: if (ex.Message == "The

Should WebException.Response.GetResponseStream() be close / disposed?

别来无恙 提交于 2019-12-08 17:58:26
问题 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 stream and this caused big problems. Because GetResponseStream() (always? / sometimes?) returns the same instance. So when I get the response stream and then dispose it, then maybe rethrow the exception to another layer that also gets the response

Handling HttpPostedFile in C#

血红的双手。 提交于 2019-12-08 03:18:55
问题 I have a C#.net web application that can send (by POST method) files to another application. In the second application I have the below code to retrieve the posted file. HttpPostedFile hpf = Request.Files[0]; Now I can save the file by the code hpf.SaveAs("The path to be saved"); But I need to send it again to another application without saving it here (without saving in 2nd appln I need to send it to a third appln). (Now I can do is that save the file in second application and from there

The underlying connection was closed: An unexpected error occurred on a receive

拥有回忆 提交于 2019-12-06 17:25:52
问题 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 kind of Exceptions returned by my function : (sorry it's in french) System.Net.WebException: La connexion sous-jacente a été fermée : Une erreur inattendue s'est produite lors de la réception. à System.Net.FtpWebRequest.CheckError() à System.Net

The underlying connection was closed: An unexpected error occurred on a receive

不想你离开。 提交于 2019-12-04 22:56:32
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 kind of Exceptions returned by my function : (sorry it's in french) System.Net.WebException: La connexion sous-jacente a été fermée : Une erreur inattendue s'est produite lors de la réception. à System.Net.FtpWebRequest.CheckError() à System.Net.FtpWebRequest.SyncRequestCallback(Object obj) à System.IO.Stream.Close() à System.Net.ConnectionPool

Get Error number in WebException Error

柔情痞子 提交于 2019-12-03 23:32:03
How To Get Error number in WebException Error? try { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("site"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); int i = stream.ReadByte(); } catch (WebException e) { //How To Get Error number in WebException Error? } You'll want to run a test to make sure that it was a ProtocolError : if (e.Status == WebExceptionStatus.ProtocolError) { Console.WriteLine("Status Code : {0}", ((HttpWebResponse)e.Response).StatusCode); Console.WriteLine("Status Description : {0}", (