473,386 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Get server errordescrition

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
Dec 19 '07 #1
5 1112
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)
"Dirk.Reimers" wrote:
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
Dec 19 '07 #2
On 19 Dez., 18:13, bruce barker
<brucebar...@discussions.microsoft.comwrote:
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)

"Dirk.Reimers" wrote:
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
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

Dec 19 '07 #3
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)
"Dirk.Reimers" wrote:
On 19 Dez., 18:13, bruce barker
<brucebar...@discussions.microsoft.comwrote:
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)

"Dirk.Reimers" wrote:
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

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

Dec 19 '07 #4
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
Dec 20 '07 #5
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
Dec 20 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Phil | last post by:
I am using a Pascal like language (Wealth-Lab) on W2K and call this server: class HelloWorld: _reg_clsid_ = "{4E797C6A-5969-402F-8101-9C95453CF8F6}" _reg_desc_ = "Python Test COM Server"...
6
by: Nathan Sokalski | last post by:
I want to set up SQL Server on Windows XP Pro so that I can use the database capabilities of ASP and IIS. I am probably using some incorrect settings, but I am not sure what they are. Here is what...
2
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000...
0
by: Philip Trim | last post by:
General Brief: 3 SQL Servers as MS SQL Server 2000 Standard Edition with Service Pack 3 All using FTP for snapshots All Servers are both Publishers and Distributors. Server A has the correct...
5
by: Grim Reaper | last post by:
My work let me put SQL Server 7.0 Enterprise Edition on my laptop. I have never setup a server from the beginning, so I am a little new at creating server groups. Alright, I am trying to create...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
14
by: Developer | last post by:
Hello All, i have recently installed VS2005 and was trying to install SQL sever 2000. I have Win XP' SP2. But when I tried installing, it only installed client tools and not the database. Can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.