Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8832871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:38:22+00:00 2026-06-14T08:38:22+00:00

I am trying to make a command line based HTTP post to a webpage,

  • 0

I am trying to make a command line based HTTP post to a webpage, where this command line can login and retrieve some data or do other things. I have all the code in place but it does not like non-static things in the static field Main, how do I fix this?

 static void Main(string[] args)
    {
        System.Console.Title = "Test Project";
        bool GoodUsername = false;
        string Username = "";
        while (GoodUsername == false)
        {
            Console.WriteLine("Please enter your username.");
             Username = Console.ReadLine();
            Console.WriteLine("Is " + Username + " correct? Type Yes or No");
            string YesNo = Console.ReadLine();
            if (YesNo == "yes" || YesNo == "Yes" || YesNo == "y")
            {
                GoodUsername = true;
                //return;
            }      
        }
        bool GoodPassword = false;
        string Password = "";           
        while (GoodPassword == false)
        {
            Console.WriteLine("Please enter your password.");
            Password = Console.ReadLine();
            Console.WriteLine("Attempting to log in.");
               string PostURL = "username=" + Username + "&password=" + Password + "&login=Login";
              string URLs = "http://c-rpg.net/index.php?page=login";
             string Response = CRPG.CRPG.DoPost(URLs, PostURL);                       
        }
    }       

Is my Code from one Class.

 string Response = CRPG.CRPG.DoPost(URLs, PostURL);             

Gives me the error.

 CookieContainer cookies = new CookieContainer();
    protected string DoPost(string URLr, string POST)
    {
        Uri url = new Uri(URLr);
        HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);

        HttpWRequest.Headers.Set("Pragma", "no-cache");
        HttpWRequest.Timeout = 5000;
        HttpWRequest.Method = "POST";
        HttpWRequest.ContentType = "application/x-www-form-urlencoded";
        HttpWRequest.CookieContainer = cookies;

        byte[] PostData = System.Text.Encoding.ASCII.GetBytes(POST);
        HttpWRequest.ContentLength = PostData.Length;
        Stream tempStream = HttpWRequest.GetRequestStream();
        tempStream.Write(PostData, 0, PostData.Length);
        tempStream.Close();

        HttpWebResponse HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
        Stream receiveStream = HttpWResponse.GetResponseStream();
        StreamReader readStream = new StreamReader(receiveStream);

        string rcstr = "";
        Char[] read = new Char[256];
        int count = 0;
        while ((count = readStream.Read(read, 0, 256)) > 0)
        {
            rcstr += new String(read, 0, count);
        }
        HttpWResponse.Close();
        readStream.Close();
        return rcstr;
    }

I can make it public and it gives me the error.

Error   1   An object reference is required for the non-static field, method, or property 'CRPG.CRPG.DoPost(string, string)'    c:\users\sales\documents\visual studio 2010\Projects\Test_CL\Test_CL\Program.cs 40
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:38:23+00:00Added an answer on June 14, 2026 at 8:38 am

    DoPost() and the cookies field are instance members.
    You need an instance of that class to call them on.

    You probably want to make them static instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to make a module, command-line-like application. Each module can hold multiple
I'm trying to make a HTML file with command line, but there is one
I'm learning Objective-C and trying to make a very simple command line calculator. 'S'
I'm trying to make this command: sed bla bla filename | awk '{printf %s
I'm trying to make a parser for a Java Program's command line arguments, as
I'm trying to install some libraries using Perl from the command line: perl -MCPAN
Ok I am trying to make a project from a command line ( not
I'm trying to make Zend's command line tool to work in Aptana's terminal view
I am trying to make a simple command line client for accessing shares via
I am trying to make a repeated call on the windows command line from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.