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

  • Home
  • SEARCH
  • 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 3609812
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:40:29+00:00 2026-05-18T21:40:29+00:00

I found this snippet of code here that allows you to log into a

  • 0

I found this snippet of code here that allows you to log into a website and get the response from the logged in page. However, I’m having trouble understanding all the part of the code. I’ve tried my best to fill in whatever I understand so far. Hope you guys can fill in the blanks for me. Thanks

string nick = "mrbean";
string password = "12345";

//this is the query data that is getting posted by the website. 
//the query parameters 'nick' and 'password' must match the
//name of the form you're trying to log into. you can find the input names 
//by using firebug and inspecting the text field
string postData = "nick=" + nick + "&password=" + password;

// this puts the postData in a byte Array with a specific encoding
//Why must the data be in a byte array?
byte[] data = Encoding.ASCII.GetBytes(postData);

// this basically creates the login page of the site you want to log into
WebRequest request = WebRequest.Create("http://www.mrbeanandme.com/login/");

// im guessing these parameters need to be set but i dont why?
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;

// this opens a stream for writing the post variables. 
// im not sure what a stream class does. need to do some reading into this.
Stream stream = request.GetRequestStream();

// you write the postData to the website and then close the connection?
stream.Write(data, 0, data.Length);
stream.Close();

// this receives the response after the log in
WebResponse response = request.GetResponse();
stream = response.GetResponseStream();

// i guess you need a stream reader to read a stream?
StreamReader sr = new StreamReader(stream);

// this outputs the code to console and terminates the program
Console.WriteLine(sr.ReadToEnd());
Console.ReadLine();
  • 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-05-18T21:40:30+00:00Added an answer on May 18, 2026 at 9:40 pm

    A Stream is a sequence of bytes.

    In order to use text with a Stream, you need to convert it into a sequence of bytes.

    This can be done manually with the Encoding classes or automatically with StreamReader and StreamWriter. (which read and write strings to streams)


    As stated in the documentation for GetRequestStream,

    You must call the Stream.Close method to close the stream and release the connection for reuse. Failure to close the stream causes your application to run out of connections.


    The Method and Content-* properties reflect the underlying HTTP protocol.

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

Sidebar

Related Questions

I was wondering what this snippet exactly does? (found here: http://code.google.com/p/google-app-engine-samples/source/browse/trunk/django_example/django_bootstrap.py ) # Make
I found this tease of a code snippet: http://codepaste.net/m6xsdi slickGrid.AddColumn( Column.ForId(riga) .Named(Riga) .ForField(id) .WithEditorFunction(TextCellEditor)
I have mysterious happenings in my code. Here's the snippet from the bean: public
Today I found this code snippet: <object ID=FF CLASSID=clsid:guid CODEBASE=url VIEWASTEXT></object> <object ID=FileSaver CLASSID=clsid:guid
I am working with a CMS that needs pretty urls. I found this snippet
Reading this question I found this as (note the quotation marks) code to solve
I found this open-source library that I want to use in my Java application.
I found this via google: http://www.mvps.org/access/api/api0008.htm '******************** Code Start ************************** ' This code was
I found this page describing the Muenchian method, but I think I'm applying it
First off, here is the situation. I'm using a guild hosting site that allows

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.