Click to See Complete Forum and Search --> : Inaccessible Due to its protection Level


greee
December 4th, 2008, 02:38 PM
Ive read a bunch of posts indicating this is mostly about needing to have an other than Private member. . .but I cant seem to make this work no matter what I make public. . .what am I doing wrong. Im a newbie to 2008.Net and C#! Any help is greatly appreciated.

using System;
using System.Text;
using System.IO;
using System.Web;
using System.Net;
using System.Collections.Specialized;

public static void Main(string[] args)
{
// Set the 'Method' property of the 'Webrequest' to 'POST'.
HttpWebRequest myHttpWebRequest = new HttpWebRequest();
myHttpWebRequest.Method = "POST";
Console.WriteLine("\nPlease enter the data to be posted to the (http://www.ias.net) Uri :");

// Create a new string object to POST data to the Url.
string inputData = Console.ReadLine();

string postData = "Request=" + inputData;
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byte1 = encoding.GetBytes(postData);

// Set the content type of the data being posted.
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";

// Set the content length of the string being posted.
myHttpWebRequest.ContentLength = byte1.Length;

Stream newStream = myHttpWebRequest.GetRequestStream();

newStream.Write(byte1, 0, byte1.Length);
Console.WriteLine("The value of 'ContentLength' property after sending the data is {0}", myHttpWebRequest.ContentLength);

// Close the Stream object.
newStream.Close();
}

BigEd781
December 4th, 2008, 02:46 PM
Could you make it clear which line is causing the problem?

dahwan
December 5th, 2008, 06:16 AM
And use Code blocks

cilu
December 5th, 2008, 06:44 AM
HttpWebRequest's constructor is protected. So you cannot do this:

HttpWebRequest myHttpWebRequest = new HttpWebRequest();

It should be something like this:

HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);

greee
December 5th, 2008, 07:41 AM
Thanks Cilu. . .that was it exactly, and got me going and finished on this project. . .

I think at one point i tried this:

HttpWebRequest myHttpWebRequest = new HttpWebRequest(url);

But it didnt work, so I gave up on that. . .can you briefly tell me why so I can get some direction on what I need to do more reading on?

Thanks for your help!