473,404 Members | 2,178 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,404 software developers and data experts.

How to determine the returned type of a webrequest?

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

Mar 15 '06 #1
2 1692
In VB you can try

if typeof objWebRequest is HttpWebRequest then

end if

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

}
"Johannes" <jj******@gmail.com> wrote in message
news:11**********************@v46g2000cwv.googlegr 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

Mar 15 '06 #2
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" <jj******@gmail.com> wrote in message
news:11**********************@v46g2000cwv.googlegr 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

Mar 15 '06 #3

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

Similar topics

0
by: Jason | last post by:
I am trying to retrieve XML data from an ASP page. If I type the URL to the asp page into my browser (i.e. http://domain.com/getxml.asp) , I will get the xml displayed in IE. But, if I try to...
2
by: Vijayakrishna Pondala | last post by:
Hi, I am using the following C# code to connect to and download information from a URL. (The pages are on JBoss server and we are using NTLM authentication to connect to the server). ----...
4
by: Prehaut Anselme | last post by:
Hi, I need to create a WebRequest with an automatic proxy I have the specification of this porxy (host & port) I ask the user their own login and password, but the proxy tells me that the...
11
by: l.woods | last post by:
I want to set up my CATCH for a specific exception, but I really don't know which one of the multitude that it is. I am getting the exception now with Catch ex as Exception but I want to be...
1
by: Tito Meinrath | last post by:
Hi, I'm really going mad about this! Currently I'm designing a student course on web services. Because I want them to understand what's really going on when web services correspond with each...
2
by: Smokey Grindel | last post by:
Right now I am posting data to a webpage by doing the following webRequest = CType(System.Net.WebRequest.Create("http://www.domain.com/login.asp"), Net.HttpWebRequest) webRequest.Method =...
4
by: =?Utf-8?B?R3JlZw==?= | last post by:
I am a newbie to WCF so please forgive if this is an obvious question. I have the following. (Service contract) IEmployee public interface IEmployee { List<EmployeeGetEmployeeByID(string...
4
by: Barnali85 | last post by:
Hi all, I am getting "The remote server returned an error: (500) Internal Server Error" exception. I have written the following code in VS.NET2005 using C# : WebRequest wr =...
3
by: =?Utf-8?B?UmljaGFyZEBub3NwYW0ubm9zcGFt?= | last post by:
My webcam app runs OK on XP but not on Vista. Here's my code snippet that has been working up until now: System.Net.WebRequest request; System.Net.WebResponse response; request =...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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
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,...

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.