CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2008
    Posts
    2

    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();
    }

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Inaccessible Due to its protection Level

    Could you make it clear which line is causing the problem?

  3. #3
    Join Date
    Mar 2007
    Posts
    375

    Re: Inaccessible Due to its protection Level

    And use Code blocks
    Please vote the posts you find usefull.

    ---

    I'm back
    Bigger and badder
    Better and bolder
    Explaining stuff -
    With an improved vocabulary!

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    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);
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    Dec 2008
    Posts
    2

    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
  •  





Click Here to Expand Forum to Full Width

Featured