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 6733631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:47:33+00:00 2026-05-26T10:47:33+00:00

Now, first off, I want to understand whether or not its better to use

  • 0

Now, first off, I want to understand whether or not its better to use HttpWebRequest and Response or whether its better to simply use a webbrowser control. Most people seem to prefer to use the web browser, however whenever I ask people about it, they tell me that HttpWebRequest and Response is better. So, if this question could be avoided by switching to a web browser (and there’s a good reason as to why its better), please let me know!

Basically, I set up a test site, written in PHP, running on localhost. It consists of three files….

The first is index.php, which just contains a simple login form, all the session and everything is just me testing how sessions work, so its not very well written, like I said, its just for testing purposes:

<?php
session_start();
$_SESSION['id'] = 2233;
?>

<form method="post" action="login.php">
U: <input type="text" name="username" />
<br />
P: <input type="password" name="password" />
<br />
<input type="submit" value="Log In" />
</form>

Then, I have login.php (the action of the form), which looks like:

<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];

if ($username == "username" && $password == "password" && $_SESSION['id'] == 2233)
{
    header('Location: loggedin.php');
    die();
}
else
{
    die('Incorrect login details');
}

?>

And lastly, loggedin.php just displays “Success!” (using the

element).

As you can see, a very simple test, and many of the things I have there are just for testing purposes.

So, then I go to my C# code. I created a method called “HttpPost”. It looks like:

private static string HttpPost(string url)
{
    request = HttpWebRequest.Create(url) as HttpWebRequest;
    request.CookieContainer = cookies;
    request.UserAgent = userAgent;
    request.KeepAlive = keepAlive;
    request.Method = "POST";

    response = request.GetResponse() as HttpWebResponse;

    if (response.StatusCode != HttpStatusCode.Found)
        throw new Exception("Website not found");

    StreamReader sr = new StreamReader(response.GetResponseStream());
    return sr.ReadToEnd();
}

I built a Windows Form application, so in the button Click event, I want to add the code to call the HttpPost method with the appropriate URL. However, I’m not really sure what I’m supposed to put there to cause it to log in.

Can anyone help me out? I’d also appreciate some general pointers on programatically logging into websites!

  • 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-26T10:47:33+00:00Added an answer on May 26, 2026 at 10:47 am

    Have you considered using WebClient?

    It provides a set of abstract methods for use with web pages, including UploadValues, but I’m not sure if that would work for your purposes.

    Also, it’s probably better not to use WebBrowser as that’s a full blown web browser that can execute scripts and such; HttpWebRequest and WebClient are much more light weight.

    Edit : Login to website, via C#

    Check this answer out, I think this is exactly what you’re looking for.

    Relevant code snippet from above link :

    var client = new WebClient();
    client.BaseAddress = @"https://www.site.com/any/base/url/";
    var loginData = new NameValueCollection();
    loginData.Add("login", "YourLogin");
    loginData.Add("password", "YourPassword");
    client.UploadValues("login.php", "POST", loginData);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off: I do not want to use JQuery, i know it would make
First off, I want to say there is no use case for this. The
First off I am very new to Objective C and iPhone programming. Now that
first, I can't stand Crystal! Okay, that's off my chest... Now, we have an
I have two destinations now and the first calls a SOAP webservice. I want
The first part of this question is now its own, here: Analyzing Text for
I create my first iphone app now i want submit this on appstore so
First off, I want to apologize beforehand, as I know there is a lot
First off, I want to thank you for looking into my question as I
First off, sorry about the long post. Figured it's better to give context to

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.