Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to determine the returned type of a webrequest?

Reply
Thread Tools

How to determine the returned type of a webrequest?

 
 
Johannes
Guest
Posts: n/a
 
      03-15-2006
When you do a webrequest like:
Dim objWebRequest As WebRequest = WebRequest.Create(objURI)
the returned class can be httpwebrequest, ftpwebrequest or any othe
descendant webrequest type that is registered on the system. How can I
determine which type is returned.

I tried if (objWebRequest is System.Net.HttpWebRequest) then .....

But the system says I am not allowed to use types in expressions.
--
BC30691: 'HttpWebRequest' is a type in 'Net' and cannot be used as an
expression.
--

How should it be done?

Johannes

 
Reply With Quote
 
 
 
 
Geoffrey Samper
Guest
Posts: n/a
 
      03-15-2006
In VB you can try

if typeof objWebRequest is HttpWebRequest then

end if

in C#
if (d is System.Net.HttpWebRequest)
{

}


"Johannes" <> wrote in message
news: oups.com...
> When you do a webrequest like:
> Dim objWebRequest As WebRequest = WebRequest.Create(objURI)
> the returned class can be httpwebrequest, ftpwebrequest or any othe
> descendant webrequest type that is registered on the system. How can I
> determine which type is returned.
>
> I tried if (objWebRequest is System.Net.HttpWebRequest) then .....
>
> But the system says I am not allowed to use types in expressions.
> --
> BC30691: 'HttpWebRequest' is a type in 'Net' and cannot be used as an
> expression.
> --
>
> How should it be done?
>
> Johannes
>



 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      03-15-2006
The WebRequest class returns the appropriate type for the URI scheme passed
to it. Therefore, all you have to do is parse the URI to get the scheme from
it to know what type you will get back.

The .Net Framework supports 3 specific schemes for this method: http://,
https://, and file:// - ti will always be one of these. You can use the Uri
class's "Scheme" property to discover this.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer

Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.

"Johannes" <> wrote in message
news: oups.com...
> When you do a webrequest like:
> Dim objWebRequest As WebRequest = WebRequest.Create(objURI)
> the returned class can be httpwebrequest, ftpwebrequest or any othe
> descendant webrequest type that is registered on the system. How can I
> determine which type is returned.
>
> I tried if (objWebRequest is System.Net.HttpWebRequest) then .....
>
> But the system says I am not allowed to use types in expressions.
> --
> BC30691: 'HttpWebRequest' is a type in 'Net' and cannot be used as an
> expression.
> --
>
> How should it be done?
>
> Johannes
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determine if more than one row returned CJM ASP General 11 07-12-2006 01:56 PM
Dataset - determine if no records are returned =?Utf-8?B?U2FuZHk=?= ASP .Net 4 04-16-2005 03:51 PM
how to determine type-type? Gernot Frisch C++ 3 01-13-2005 07:34 AM
What "type" is returned? Lasse Edsvik ASP .Net 2 09-24-2004 12:49 PM
nuby: determine method passed and determine the receiver that received the method Peņa, Botp Ruby 1 01-24-2004 07:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57