4 Replies - 876 Views - Last Post: 27 July 2013 - 08:14 AM Rate Topic: -----

#1 Oli999  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 26-July 13

How to login to a website with c#

Posted 26 July 2013 - 09:17 AM

I'm wanting to login to this website

http://www.conquercl...p?game=13025037

and return all the html using httpwebrequest

Code:-
var request = WebRequest.Create("http://www.conquerclub.com/game.php?game=13025037");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string result = reader.ReadToEnd();


This re-directs to the login page as expected and returns that. I'm looking for a way to send the username and password to automatically login and go to the right page. I've already had a look of lots of similar questions and tried a few different things but can;t get anything to work. It always re-directs and can only ever get the login page back. I'm a decent c# programmer but don't really understand how the web login stuff works with PHP e.t.c. I've already spent several hours trying to figure this out so if anyone can provide me with a bit of code that will make this work will be hugely appreciated.

login details (this is a real account I've created)

username - testuser1
password - testing

This is the HTML from the login section of the page source:-

<form class="ccform" action="login.php" method="post" onsubmit="login();">
<fieldset>
<legend>Login</legend>
<div class="field-row">
<label for="username">Username</label>
<input type="text" class="field" name="username" id="username" autofocus maxlength="16" value="" tabindex="1" />
</div>
<div class="field-row">
<label for="password">Password</label>
<input type="password" class="field" name="password" id="password" maxlength="16" tabindex="2" />
</div>
<div class="field-row">
<input type="hidden" name="direct" id="direct" value="yes" />
<input type="hidden" name="redirect" value="" />
<input type="hidden" name="protocol" value="HTTP" />
<input type="submit" class="button-inline" name="submit" value="Login" tabindex="3" />
</div>
<div class="field-row">
<p><a href="public.php?mode=forgot" tabindex="4">I forgot my login</a></p>
</div>
</fieldset>
</form>

Is This A Good Question/Topic? 0
  • +

Replies To: How to login to a website with c#

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9493
  • View blog
  • Posts: 35,827
  • Joined: 12-June 08

Re: How to login to a website with c#

Posted 26 July 2013 - 09:24 AM

Are you planning on running a bot on the site? They don't seem to like that.
Was This Post Helpful? 0
  • +
  • -

#3 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: How to login to a website with c#

Posted 26 July 2013 - 11:49 AM

You'd need to imitate a user completely. That includes first interfacing with the login page.

You should take a look into the CookieContainer.
Was This Post Helpful? 0
  • +
  • -

#4 Oli999  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 26-July 13

Re: How to login to a website with c#

Posted 27 July 2013 - 02:10 AM

View Postmodi123_1, on 26 July 2013 - 09:24 AM, said:

Are you planning on running a bot on the site? They don't seem to like that.


Depends how you define "bot". They have a basic API and one of it's features is specifically for mods to periodically check game status. There's already an existing mod downloadable from the CC enhancements forum that uses this to access once per minute so can't see that there's going to be any objection if mine does the same thing.
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3650
  • View blog
  • Posts: 11,419
  • Joined: 05-May 12

Re: How to login to a website with c#

Posted 27 July 2013 - 08:14 AM

And they even have a developer's section... http://www.conquercl...p?f=529&t=73672

Perhaps you may get more help there about being able to logon to their system.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1