Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1679
  • Last Modified:

Generate PostData value for WebBrowser

Hi,

I want download page from a site that required login before entering.
I have username and password for the site, but want enter it programatically (without manually entering username/password on site logon page).

I tried use webbrowser for the task.
I found that I can use OnBeforeNavigate2 event.
There is parameter PostData that provides required information for the server.

Question is : how to generate a value of PostData parameter?

Regards.
0
Slavak
Asked:
Slavak
  • 3
1 Solution
 
EddieShipmanCommented:
Here's how to do it with the Indy idHTTP component.

procedure TForm1.SendPostData;
Var
  aStream: TMemoryStream;
  Params: TStringStream;
begin
  aStream := TMemoryStream.create;
  Params := TStringStream.create('');

  try
    with IdHTTP1 do
    begin
      Params.WriteString(URLEncode('teste=' + 'yes' + '&'));
      Params.WriteString(URLEncode('name=' + 'ivan' + '&'));
      Params.WriteString(URLEncode('number=' + '102'));
      Request.ContentType := 'application/x-www-form-urlencoded';
      try
        Post('http://localhost/teste.asp', Params, aStream);
      except
        on E: Exception do
          showmessage('Error encountered during POST: ' + E.Message);
      end;
    end;
  aStream.WriteBuffer(#0' ', 1);
  aStream.Position := 0;
  Memo1.Lines.LoadFromStream(aStream);
  except
  end;
end;

Here is how using TWebBrowser:
http://www.members.shaw.ca/iedelphi/webbrowser.htm#advanced9
0
 
SlavakAuthor Commented:
Thanks, Eddie.

Points yours, but can you answer me for some related questions?

-- does Indy components provides support for https protocol?
-- does Indy can download web pages faster then webbrowser?
-- do you know any other free Delphi component that can download http/https pages faster?

Slava.

P.S. I will be glad to get answer for this questions from anyone. I will give aditional points for the answer.
0
 
EddieShipmanCommented:
Yes
Yes
don't know
0
 
EddieShipmanCommented:
If you are not needing to interact with the page, I'd suggest using idHTTP because you only
get back the HTML, not the images, objects, etc...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now