Quantcast

Jump to content


Photo

[Delphi] Help with login script


  • Please log in to reply
4 replies to this topic

#1 Basstar

Basstar
  • 98 posts

Posted 26 July 2011 - 11:35 AM

Hi i used the wrapper from the snippet section and want to make a neopets login(after that some more)

but i have some slight problems.... I can post the name with this script but i cant input the pw... or i have to include a cookie.. don't know what it's wrong so it would be n1 if somebody can help me with this...


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP,
  StdCtrls, StrUtils, IdZlibCompressorBase, ZLib, OleCtrls, SHDocVw;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    Button2: TButton;
    Memo1: TMemo;
    Button3: TButton;
    WebBrowser1: TWebBrowser;
    Edit2: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  type WebRequest = class
  private
    strBuff: String;
    sck: TIdHTTP;
    prevPage: String;
    useGZ: Boolean;
    procedure SetHeader(strRef: String);
  public
    constructor Create(UseGZip : Boolean);
    function Get(strURL, strReferer: String): String;
    function Post(strURL: String; strPacket: TStringStream; strReferer: String): String;
  published
    property LastPage: String
      read prevPage
      write prevPage;
    property CurrentBuffer: String
      read strBuff
      write strBuff;
    property AllowGZip: Boolean
      read useGZ
      write useGZ;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

constructor WebRequest.Create(UseGZip : Boolean);
begin
  sck := TIdHTTP.Create();
  useGZ := UseGZip;
  if useGZ = true then sck.Compressor := TIdZlibCompressorBase.Create(nil);
  sck.AllowCookies := true;
  prevPage := 'http://www.google.ca/';
end;

function WebRequest.Get(strURL, strReferer: String): String;
var
  strHTML: String;
  strRet,strDcmp: TStringStream;
begin
  strRet := TStringStream.Create('');
  strDcmp := TStringStream.Create('');
  SetHeader(strReferer);

  sck.Get(strURL, strRet);
  if sck.Response.ContentEncoding = 'gzip' then
  begin
    sck.Compressor.DecompressGZipStream( strRet, strDcmp);
    strHTML := strDcmp.DataString;
  end
  else
  begin
     strHTML := strRet.DataString;
  end;

  prevPage := strURL;
  strBuff := strHTML;
  strRet.Free;
  strDcmp.Free;
  Result := strHTML;
end;

function WebRequest.Post(strURL: String; strPacket: TStringStream; strReferer: String): String;
var
  strRet,strDcmp: TStringStream;
  strHTML: String;
begin
if sck.Connected = true then
  begin
    sck.Disconnect;
     while sck.Connected = true do
      Application.ProcessMessages;
  end;
  SetHeader(strReferer);

  strRet := TStringStream.Create('');
  strDcmp := TStringStream.Create('');

  sck.Post(strURL, strPacket, strRet);
  if sck.Response.ContentEncoding = 'gzip' then
  begin
    sck.Compressor.DecompressGZipStream( strRet, strDcmp);
    strHTML := strDcmp.DataString;
  end
  else
  begin
     strHTML := strRet.DataString;
  end;

  prevPage := strURL;
  strBuff := strHTML;
  strRet.Free;
  strDcmp.Free;
  Result := strHTML;
end;


procedure WebRequest.SetHeader(strRef: String);
begin
  sck.Request.UserAgent := 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050414 Firefox/1.0.3';
  sck.Request.Accept := 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/ png,*/*;q=0.5';
  sck.Request.AcceptLanguage := 'en-us,en;q=0.5';
  sck.Request.AcceptCharSet := 'ISO-8859-1,utf-8;q=0.7,*;q=0.7';
  if useGZ = true then sck.Request.AcceptEncoding := 'gzip, deflate';
  sck.Request.Referer := strRef;
  sck.Request.ContentType := 'application/x-www-form-urlencoded';
  sck.Request.Connection := 'keep-alive';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  HTTP: WebRequest;
  strHTML: String;
  strPost: TStringStream;
begin
  HTTP := WebRequest.Create(false);
  strPost := TStringStream.Create('');
  strPost.WriteString('destination=/ petcentral.phtml');
  strPost.WriteString('&username=' + edit1.Text);
  strPost.WriteString('&password=' + edit2.Text);
  label1.Caption := 'Loggin in';
  strHTML := HTTP.Post('http://www.neopets.com/hi.phtml', strPost, 'http://www.neopets.com/loginpage.phtml');
  memo1.Text:=strHTML;
  memo1.Lines.SaveToFile('C:\test.html');
  strHTML := HTTP.Post('http://www.neopets.com/objects.phtml', strPost, 'http://www.neopets.com/hi.phtml');
  memo1.Text:=strHTML;
  memo1.Lines.SaveToFile('C:\test2.html');




end;
//Get
procedure TForm1.Button2Click(Sender: TObject);
var
  HTTP: WebRequest;
  strHTML: String;
begin
  HTTP := WebRequest.Create(false);
  strHTML := HTTP.Get('http://www.neopets.com/petcentral.phtml',HTTP.LastPage);
  Memo1.Text:=strHTML;
end;
end.


#2 Pyro699

Pyro699
  • 1543 posts


Users Awards

Posted 26 July 2011 - 11:37 AM

Could you actually be a bit more specific on what your problem is? What is it not doing that you are trying to do...

#3 Basstar

Basstar
  • 98 posts

Posted 26 July 2011 - 12:22 PM

at the moment the program

1. opens the loginpage.phtml
2. it insert the username
3. then it's opening http://www.neopets.com/hi.phtml


4. now it should include the pw and log in but it doesn't do that

if i take a look on the saves it is shown the loginpage.html (test.html is the save) with my pet
but the second save(test2.html) should show me logged in but i can only see the normal page....

if you want i can upload the program and you can take a closer look on it...

Edited by Basstar, 26 July 2011 - 12:41 PM.


#4 Basstar

Basstar
  • 98 posts

Posted 27 July 2011 - 05:59 PM

After a very long day i got it fixed.... so pls close ;)

had to add


sck.HandleRedirects:=true;
sck.RedirectMaximum:=5;

and button 1 changes to


procedure TForm1.Button1Click(Sender: TObject);
var
HTTP: WebRequest;
strHTML,s,rand: String;
strPost: TStringStream;
begin
HTTP := WebRequest.Create(false);
sleep(1000);
HTTP.GET('http://www.neopets.com/' 'http://www.google.com/');
sleep(1000);
strPost := TStringStream.Create('');
strPost.WriteString('destination=');
strPost.WriteString('&&username=' + edit1.Text);
strPost.WriteString('&&password=' + edit2.Text);
rand:=inttostr(Random(33)+4);
strPost.WriteString('&&x=' + rand);
rand:=inttostr(Random(56)+4);
strPost.WriteString('&&y=' + rand);
strHTML:=HTTP.POST('http://www.neopets.com/login.phtml' strPost ,'http://www.neopets.com/');
end;

Edited by Basstar, 27 July 2011 - 06:07 PM.


#5 Basstar

Basstar
  • 98 posts

Posted 01 August 2011 - 12:47 PM

All problems are gone and i made a moneytree grabber from it.

I made a testrun today and take a look.. My program says : "grabbed Electric Petpet Paint Brush"


:D


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users