Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Get server errordescrition

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dirk.Reimers - 19 Dec 2007 16:23 GMT
Hi all,

sorry for my dumb question:

I use the following code:

       Dim request As WebRequest = HttpWebRequest.Create("http://" &
ip & _
         /TVBrowserTimerEvent?command=add")
       request.Credentials = New NetworkCredential("root", "toor")
       Try
           Dim response As HttpWebResponse =
CType(request.GetResponse(), HttpWebResponse)
       Catch ex As Exception
           MsgBox(ex.Message)
       End Try

which is working fine if the server responds with Code 200 OK

But I'm not able to get any additional info if the request goes wrong.

The servers answer is (for example):

-----
HTTP/1.1 400 Function failed.
Connection: close
Content-Length: 46
Content-Type: text/html; charset=utf-8

service name don't match.
----

But I'm only able to retrieve the 400 error code by accessing the ex
element. I do not know how to access the additional "service name
don't match." information.

Any hints?

Thanx

Dirk
bruce barker - 19 Dec 2007 17:13 GMT
there is no standard for returning errors other than the status description.
you may need to read the response content (response.GetResponseStream) to get
detail.

-- bruce (sqlwork.com)

> Hi all,
>
[quoted text clipped - 37 lines]
>
> Dirk
Dirk.Reimers - 19 Dec 2007 19:40 GMT
On 19 Dez., 18:13, bruce barker
<brucebar...@discussions.microsoft.com> wrote:
> there is no standard for returning errors other than the status description.
> you may need to read the response content (response.GetResponseStream) to get
[quoted text clipped - 43 lines]
>
> > Dirk

As far as I read i can use

          Dim response As HttpWebResponse = request.GetResponse()
          Dim responseStream As Stream = response.GetResponseStream
          Dim reader As StreamReader = New
StreamReader(responseStream)

but vb.net throw an error just after the first line (Dim response As
HttpWebResponse = request.GetResponse()) as the server send bacxk an
400 status code. The next line of code doen't get executed anymore.

Dirk
and then
bruce barker - 19 Dec 2007 21:18 GMT
dim response before the try, then you can access it in the catch. be sure to
check that it is not null which it will be if there is a connection error
rather than a bad response code.

-- bruce (sqlwork.com)

> On 19 Dez., 18:13, bruce barker
> <brucebar...@discussions.microsoft.com> wrote:
[quoted text clipped - 59 lines]
> Dirk
> and then
Dirk.Reimers - 20 Dec 2007 07:17 GMT
Hi,

here are some server communication sniffs:

everythink ok:

---
GET /TVBrowserTimerEvent?command=add
HTTP/1.1
Authorization: Basic cm9vdDpkcmVhbWJveA==

HTTP/1.1 200 OK
Connection: close
Content-Length: 37
Content-Type: text/html; charset=utf-8

event was created successfully.
----

and now the error state:

---
GET /TVBrowserTimerEvent?command=add
HTTP/1.1
Authorization: Basic cm9vdDpkcmVhbWJveA==

HTTP/1.1 400 Function failed.
Connection: close
Content-Length: 97
Content-Type: text/html; charset=utf-8

event could not be added
---
in the error case 'request' is 'Nothing' indeed and the catch can
only access the ex error.The error description mentions server code
400. So I think the communiction is quite ok (I can see a valid HTTP
connection in the ehternet sniff) and the error is not a connetcion
error code. But I am not able to get any further descrition to be
parsed as there are some different errors with the same HTTP error
code.

Thanks for you support.

Dirk
Dirk.Reimers - 20 Dec 2007 20:10 GMT
Thank you Bruce,

I finally found the correct code:

---
       Dim request As WebRequest = HttpWebRequest.Create("http://" &
ip & "/TVBrowserTimerEvent?command=add")
       request.Credentials = New NetworkCredential("root", "toor")

       Try
           Dim response As HttpWebResponse = request.GetResponse()
       Catch ex As WebException
           Dim error_response As HttpWebResponse = CType(ex.Response,
HttpWebResponse)
           Dim error_stream As Stream =
error_response.GetResponseStream
           Dim stream_content As StreamReader = New
StreamReader(error_stream)
           MsgBox(stream_content.ReadToEnd, MsgBoxStyle.Exclamation,
"Event could not be added")
       End Try

---

The clue was to ctype the exception to an httpwebresponse, than access
the webresponses stream and read it to end.

Thanx a lot

Dirk

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.