How to determine the returned type of a webrequest?

J

Johannes

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.
 
G

Geoffrey Samper

In VB you can try

if typeof objWebRequest is HttpWebRequest then

end if

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

}
 
K

Kevin Spencer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top