End Google Ads 201810 - BS.net 01 --> I'm trying to code up an app to let me auto log in and manage my Eve account as a learning experience working with viewstate and postdata ect. The issue I am having is this code I have below doesn't seem to work at all. I get an error in the browser saying that there was an error like the postdata and headers are incorrect. Could someone help me out?


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Web;

namespace Sanction_Eve
{
public partial class frmMain : Form
{
public string strUserName = "username";
public string strPassword = "password";

public frmMain()
{
InitializeComponent();
}
//BEGIN CUSTOM FUNCTIONS
private void ParseViewandEvent()
{
HtmlDocument wbBrowserDoc = wbBrowser.Document;

string strViewState = wbBrowserDoc.GetElementById("__VIEWSTATE").GetAttribute("value");
string strEventValidation = wbBrowserDoc.GetElementById("__EVENTVALIDATION").GetAttribute("value");

LogOn(strViewState, strEventValidation);
}

private void LogOn(string strViewState, string strEventValidation)
{
string PostDataStr;
byte[] PostDataByte;
string AdditionalHeaders;

PostDataStr = "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=" + strViewState + "&__VIEWSTATEENCRYPTED=&__EVENTVALIDATION=" + strEventValidation + "&ctl00$ContentPlaceHolder1$username=" + strUserName + "&ctl00$ContentPlaceHolder1$password=" + strPassword + "&ctl00$ContentPlaceHolder1$btnLogin=Login";
PostDataByte = Encoding.UTF8.GetBytes(PostDataStr);
AdditionalHeaders = "Content-Type: application/x-www-form-urlencoded" + Environment.NewLine + "Content-Length: " + PostDataStr.Length + Environment.NewLine;
wbBrowser.Navigate("https://secure.eve-online.com/login.aspx?", "", PostDataByte, AdditionalHeaders);

do
{
Application.DoEvents();
} while (wbBrowser.ReadyState != WebBrowserReadyState.Complete);
}
//END CUSTOM FUNCTIONS

private void btnGo_Click(object sender, EventArgs e)
{
wbBrowser.Navigate("https://secure.eve-online.com/login.aspx?");
do{Application.DoEvents();} while (wbBrowser.ReadyState != WebBrowserReadyState.Complete);

ParseViewandEvent();
}
}
}



This is the POST I get using FireFox TamperData. It is what I used to form my own post above.


19:13:02.932[309ms][total 309ms] Status: 302[Found]
POST https://secure.eve-online.com/login.aspx Load Flags[LOAD_DOCUMENT_URI LOAD_INITIAL_DOCUMENT_URI ] Content Size[22807] Mime Type[text/html]
Request Headers:
Host[secure.eve-online.com]
User-Agent[Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 4.0.20506)]
Accept[text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8]
Accept-********[en-us,en;q=0.5]
Accept-Encoding[gzip,deflate]
Accept-Charset[ISO-8859-1,utf-8;q=0.7,*;q=0.7]
Keep-Alive[300]
Connection[keep-alive]
Referer[https://secure.eve-online.com/login.aspx]
******
Post Data:
__EVENTTARGET[]
__EVENTARGUMENT[]
__VIEWSTATE[VIEWSTATE DATA WAS HERE(REMOVED FOR SECURITY PURPOSES)]
__VIEWSTATEENCRYPTED[]
__EVENTVALIDATION[ EVENTVALIDATION DATA WAS HERE(REMOVED FOR SECURITY PURPOSES)
ctl00%24ContentPlaceHolder1%24username[USERNAME]
ctl00%24ContentPlaceHolder1%24password[PASSWORD]
ctl00%24ContentPlaceHolder1%24btnLogin[Login]