Link to home
Start Free TrialLog in
Avatar of snowdog_2112
snowdog_2112Flag for United States of America

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)WebRequest.Create("http://www.mysite.com/x.asp");


The error is: WebRequest does not exist in the current context.

HELP?!?!?!

ASKER CERTIFIED SOLUTION
Avatar of Gagan_Jaura
Gagan_Jaura

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of snowdog_2112

ASKER

I fxed it.  

First, I found syntax to make it work:

System.Net.HttpWebRequest objRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.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.

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.