The twebbrowser component post data in Delphi and obtain the webpage source file

Source: Internet
Author: User

Unit unit1;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, stdctrls, olectrls, shdocvw;

Type
Tform1 = Class (tform)
Webbrowser1: twebbrowser;
Memo1: tmemo;
Button1: tbutton;
Procedure button1click (Sender: tobject );
*******
{Private Declarations}
Public
{Public declarations}
End;

VaR
Form1: tform1;

Implementation

{$ R *. DFM}

procedure tform1.button1click (Sender: tobject);
var
URL: olevariant;
post: olevariant;
Target: olevariant;
flag: olevariant;
header: olevariant;
poststr: string;
postlen, index: integer;
begin
URL: = 'HTTP: // port.fudan.edu.cn: 58080/amserver/UI/login? Goto = http % 3A % 2f % 2fwww.urp.fudan.edu.cn % 3a81% 2 fepstar % 2fr % 2fpr % 2 fgwkh % 2 fdzgwkh % 2fgr_dzgwkh_index.jsp & gotoonfail = http://www.urp.fudan.edu.cn/portal ?. Flag = fail ';
poststr: = 'login. token1 = 04538 & login. token2 = ******** & submit = % B5 % C7 + % C2 % BC ';
Target: = NULL;
flag: = 0;
postlen: = length (poststr);
// build a variant array of the varbyte type.
post: = vararraycreate ([0, (postlen-1)], varbyte);
// fill in data
for index: = 0 to postlen-1 do
post [Index]: = ord (poststr [index + 1]);
// fill the header data Note: application
header: = 'content-type: application/X-WWW-form-urlencoded ';

Webbrowser1.navigate2 (URL, flag, target, post, header );
While webbrowser1.busy = true do
Application. processmessages;
If webbrowser1.readystate = readystate_complete then
Memo1.text: = webbrowser1.oleobject. Document. All. Tags ('html'). Item (0). outerhtml;
Else
Memo1.text: = 'page loading failed ';
End;

End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.