snowdog_2112
asked on
c# system.net.httpwebrequest error
My head is swimming...
VS 2008 Express with c#
I have added System.Net in the References, and included "Using System.Net" in the service1.cs file. I'm working in the service1.Designer.cs file.
Every indication is that you have to do:
HttpWebRequest objRequest;
objRequest = (HttpWebRequest)WebRequest .Create("http://www.mysite.com/x.aspx" );
First of all,
HttpWebRequest objRequest; <-- gives error
So I add the explicit reference to (Sytem.Net):
System.Net.HttpWebRequest objRequest; <-- no error
I also added the reference in the "objRequest =" line but I *STILL* get an error on the WebRequest:
objRequest = (System.Net.HttpWebRequest )WebReques t.Create(" http://www.mysite.com/x.asp");
The error is: WebRequest does not exist in the current context.
HELP?!?!?!
VS 2008 Express with c#
I have added System.Net in the References, and included "Using System.Net" in the service1.cs file. I'm working in the service1.Designer.cs file.
Every indication is that you have to do:
HttpWebRequest objRequest;
objRequest = (HttpWebRequest)WebRequest
First of all,
HttpWebRequest objRequest; <-- gives error
So I add the explicit reference to (Sytem.Net):
System.Net.HttpWebRequest objRequest; <-- no error
I also added the reference in the "objRequest =" line but I *STILL* get an error on the WebRequest:
objRequest = (System.Net.HttpWebRequest
The error is: WebRequest does not exist in the current context.
HELP?!?!?!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I fxed it.
First, I found syntax to make it work:
System.Net.HttpWebRequest objRequest = (System.Net.HttpWebRequest )System.Ne t.WebReque st.Create( sURL);
This led me to believe the "using System.Net" was not inherited from the service1.cs file to the .designer file.
I had to include in the service1.designer.cs file:
using System;
using System.Configuration;
using System.Net;
using System.IO;
Now I can refer to them without referencing the full path.
First, I found syntax to make it work:
System.Net.HttpWebRequest objRequest = (System.Net.HttpWebRequest
This led me to believe the "using System.Net" was not inherited from the service1.cs file to the .designer file.
I had to include in the service1.designer.cs file:
using System;
using System.Configuration;
using System.Net;
using System.IO;
Now I can refer to them without referencing the full path.
ASKER
See my post below this answer about including "using System.Net" in the service1.designer.cs file - this answer fixed my error, but including the System.Net makes it easier to code without having to include the full path.
http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx
Arun