idhttp问题 在线等解答
代码如下-------unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, ExtCtrls, ComCtrls, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, StdCtrls,ActiveX;
type
TForm1 = class(TForm)
Panel1: TPanel;
StatusBar1: TStatusBar;
IdHTTP1: TIdHTTP;
Memo1: TMemo;
Panel2: TPanel;
WebBrowser1: TWebBrowser;
Button3: TButton;
Button4: TButton;
Button5: TButton;
procedure FormShow(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
function ShowHtml(mWebBrowser: TWebBrowser; mStrings: TStrings): Boolean;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
MyCookList:string;
Response: TStringStream;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
end;
procedure TForm1.Button3Click(Sender: TObject);
var
Fpost : Tstrings;
i:integer;
Cookie:string;
begin
Response := TStringStream.Create('');
Fpost:=TStringList.Create;
Fpost.clear;
Fpost.Add('strURL=http://igame.');
Fpost.Add('Mode=Login');
Fpost.Add('strMethod=nmmain');
Fpost.Add('ID=2aê?μ?1ú');
Fpost.Add('PWD=46443258');
Fpost.Add('isagree=checked');
IdHTTP1.Request.Referer:='http://igame.';
IdHTTP1.Request.From :='http://igame.';
IdHTTP1.post('http://igame.',Fpost,Response);
for i:=0 to IdHTTP1.Response.RawHeaders.Count-1 do
begin
if UpperCase(Copy(IdHTTP1.Response.RawHeaders[i],1,10)) = 'SET-COOKIE' then
begin
Cookie:=Trim(Copy(IdHTTP1.Response.RawHeaders[i],12,MAXINT));
Cookie:=Copy(Cookie,1,Pos(';',Cookie));
MyCookList :=MyCookList+Cookie;
end;
end;
IdHTTP1.Request.RawHeaders.Add('Cookie:'+MyCookList);
memo1.text:=Response.DataString;
ShowHtml(WebBrowser1,Memo1.Lines);
end;
function TForm1.ShowHtml(mWebBrowser: TWebBrowser; mStrings: TStrings): Boolean;
var
vMemoryStream: TMemoryStream;
begin
Result := False;
if not (Assigned(mStrings) and Assigned(mWebBrowser)) then Exit;
mWebBrowser.Navigate('about:blank');
if not Assigned(mWebBrowser.Document) then Exit;
vMemoryStream := TMemoryStream.Create;
try
mStrings.SaveToStream(vMemoryStream);
try
vMemoryStream.Position := 0;
Application.ProcessMessages; // :)
(mWebBrowser.Document as IPersistStreamInit).Load(
TStreamAdapter.Create(vMemoryStream));
except
Exit;
end;
finally
vMemoryStream.Free;
end;
Result := True;
end; { ShowHtml }
procedure TForm1.Button4Click(Sender: TObject);
begin
memo1.text:=Response.DataString;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
ShowHtml(WebBrowser1,Memo1.Lines);
end;
end.
运行结果------
<SCRIPT LANGUAGE="JAVASCRIPT">
document.domain="
<!--
parent.location.reload();
//-->
</SCRIPT>
当前脚本错误
行:3
字符:4
错误:未指明错误
代码:0
URL:about blank
----------------
在线等解答,谢谢