|
-
December 4th, 2008, 03:38 PM
#1
Inaccessible Due to its protection Level
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();
}
-
December 4th, 2008, 03:46 PM
#2
Re: Inaccessible Due to its protection Level
Could you make it clear which line is causing the problem?
-
December 5th, 2008, 07:16 AM
#3
Re: Inaccessible Due to its protection Level
Please vote the posts you find usefull.
---
I'm back
Bigger and badder
Better and bolder
Explaining stuff -
With an improved vocabulary!
-
December 5th, 2008, 07:44 AM
#4
Re: Inaccessible Due to its protection Level
HttpWebRequest's constructor is protected. So you cannot do this:
Code:
HttpWebRequest myHttpWebRequest = new HttpWebRequest();
It should be something like this:
Code:
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
-
December 5th, 2008, 08:41 AM
#5
Re: Inaccessible Due to its protection Level
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|