473,498 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get value from object?

I'm having difficults getting at values of an object. Here is my code,
which only gets a webpage. The two values I can't reach have comments next
to them. I've also listed the watches tree and with values I'd like to get
within the wResp object.

Dim wReq As WebRequest = WebRequest.Create(url)
If TypeOf wReq Is HttpWebRequest Then
CType(wReq, HttpWebRequest).UserAgent = "Mozilla/4.0
(compatible; MSIE 6.0; Windows NT 5.1; Feedreader; .NET CLR 1.1.4322; .NET
CLR 2.0.40607)"
End If
Dim wResp As WebResponse = wReq.GetResponse()
myContentType = wResp.ContentType
myStatusCode= wResp.StatusCode 'this is not valid
myStatusDescription = wResp.StatusDescription 'this is not
valid

In the Watches window, the tree for wResp looks like this:

Name Value
Type
- wResp
{System.Net.HttpWebResponse} System.Net.HttpWebResponse
- {System.Net.HttpWebResponse} {System.Net.HttpWebResponse}
System.Net.HttpWebResponse
ContentType "image/gif"
String
StatusCode OK
System.Net.HttpStatusCode
StatusDescription "OK"
String

I don't see a wResp.StatusCode or wResp.StatusDescription listed in the drop
down pop hint. What am I missing to get at those values?

Also, how do I get the numerical values of response codes? Such as "OK" =
200 or "Bad request" = 400. I don't see anything like that listed in the
watch window.

Thanks,
Brett
Nov 21 '05 #1
1 1439
Brett,
Dim wResp As WebResponse = wReq.GetResponse()
You have a WebResponse variable.
myStatusCode= wResp.StatusCode 'this is not valid
However you are attempting to return HttpWebResponse values.

Seeing as the original request was a HttpWebRequest, wResp will contain an
HttpWebResponse, you need to cast the variable to HttpWebResponse to use the
values.

Dim wResp As HttpWebResponse = DirectCast(wReq.GetResponse(),
HttpWebResponse)
NOTE: CType is the convertion operator, while DirectCast is a cast operator.
CType will attempt to convert the value if a conversion is possible (a
string to an integer), while DirectCast requires the value to be the
specified type (GetResponse *is* returning a HttpWebResponse object).

Hope this helps
Jay

"Brett" <no@spam.com> wrote in message
news:e5**************@TK2MSFTNGP09.phx.gbl... I'm having difficults getting at values of an object. Here is my code,
which only gets a webpage. The two values I can't reach have comments
next to them. I've also listed the watches tree and with values I'd like
to get within the wResp object.

Dim wReq As WebRequest = WebRequest.Create(url)
If TypeOf wReq Is HttpWebRequest Then
CType(wReq, HttpWebRequest).UserAgent = "Mozilla/4.0
(compatible; MSIE 6.0; Windows NT 5.1; Feedreader; .NET CLR 1.1.4322; .NET
CLR 2.0.40607)"
End If
Dim wResp As WebResponse = wReq.GetResponse()
myContentType = wResp.ContentType
myStatusCode= wResp.StatusCode 'this is not valid
myStatusDescription = wResp.StatusDescription 'this is not
valid

In the Watches window, the tree for wResp looks like this:

Name Value Type
- wResp {System.Net.HttpWebResponse}
System.Net.HttpWebResponse
- {System.Net.HttpWebResponse} {System.Net.HttpWebResponse}
System.Net.HttpWebResponse
ContentType "image/gif" String
StatusCode OK
System.Net.HttpStatusCode
StatusDescription "OK" String

I don't see a wResp.StatusCode or wResp.StatusDescription listed in the
drop down pop hint. What am I missing to get at those values?

Also, how do I get the numerical values of response codes? Such as "OK" =
200 or "Bad request" = 400. I don't see anything like that listed in the
watch window.

Thanks,
Brett

Nov 21 '05 #2

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

Similar topics

30
1537
by: Alf P. Steinbach | last post by:
The C++ FAQ item 29.5 (this seems to be strongly related to C), at <url: http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.5> mentions that <quote> C++ guarantees a char is exactly one...
9
2910
by: ckerns | last post by:
I want to loop thru an array of controls,(39 of them...defaults = 0). If value is null or non-numeric I want to assign the value of "0". rowString = "L411" //conrol name if (isNaN(eval...
30
1369
by: Alf P. Steinbach | last post by:
The C++ FAQ item 29.5 (this seems to be strongly related to C), at <url: http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.5> mentions that <quote> C++ guarantees a char is exactly one...
4
2271
by: Jon Slaughter | last post by:
I'm reading a book on C# and it says there are 4 ways of passing types: 1. Pass value type by value 2. Pass value type by reference 3. Pass reference by value 4. Pass reference by reference. ...
275
12025
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
7126
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
7210
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7381
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5465
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4916
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1424
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
659
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
293
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.