【发布时间】:2013-10-10 22:48:19
【问题描述】:
我有一个问题,我可以使用 tIdhttp 毫无问题地连接到我想要的站点,但问题是我无法从其他按钮连接。
我已经在函数之外声明了这些变量..这会有所帮助,但它没有
var
Form1: TForm1;
HTTP : TIDHTTP;
Cookie : TidCookieManager;
implementation
{$R *.dfm}
函数中的这个
HTTP := TIDHTTP.Create(NIL);
Cookie := TidCookieManager.Create(nil);
HTTP.Request.UserAgent := 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; Acoo Browser 1.98.744; .NET CLR 3.5.30729)';
HTTP.Request.Accept := 'text/html, */*';
HTTP.Request.CacheControl := 'no-cache';
HTTP.AllowCookies := True;
HTTP.HandleRedirects := True;
HTTP.ProtocolVersion := pv1_1;
HTTP.CookieManager := Cookie;
HTTP.RedirectMaximum := 15;
Data := TStringList.Create;
Page := TStringList.Create;
Data.Add('LoginForm[username]=xxxLoginForm[password]=xxx&LoginForm[rememberMe]=0');
Page.Text := HTTP.Post('http://somesite.com/login.html',Data);
If Pos('>Logout', Page.Text) = 0 Then Result := False
else Result := True;
Page.Free;
Data.Free;
// HTTP.Free;
end;
按钮2
HTTP.Get('http://somesite.cc/info/523364d0/'); // this does not work it show that im not connected ..but the function already connected to the site.
在 button1 中,我可以使用我的功能成功连接(登录到站点)然后我使用 HTTP.get 在 button2 中单击以获取文件,但它失败了,这表明我没有登录 所以我怎样才能让我的程序保持连接,所以我只能在没有再次登录的情况下调用获取页面(在其他按钮中)。
抱歉我的英语不好。
【问题讨论】:
-
请粘贴单位的完整代码。
-
好的,我已经在函数中发布了所有代码
-
您可以使用网络浏览器登录吗?如果是这样,那么使用像 Wireshark 这样的数据包嗅探器来捕获该 HTTP 数据,然后您可以编写
TIdHTTP来复制它。您可能遗漏了网络浏览器发送和/或网络服务器需要的内容。 -
可以但不能?
-
这可能只是一个拼写错误,但您的主机名不匹配(
somesite.cc和somesite.com),而且您发布到 HTML 页面似乎很奇怪。确保您发布到表单的操作。你确定登录成功了吗?即使您可以将所有参数放在一行中,您也会缺少第一个和第二个参数之间的&分隔符。