1

我正在尝试使用 Indy 组件从站点获取数据。(这是在 Delphi 7 中,但很高兴使用任何有效的东西。)

如果您进入普通浏览器并输入路径: http: //inventory.data.xyz.com/provide_data.aspx ?ID=41100&Mixed=no?fc=true&lang=en 它会让您在重定向到之前勾选免责声明实际站点。这会创建一个 cookie,如果我在 Firefox 中查看它是这样的:http: //inventory.data.xyz.com 名称:ASP.NET_SessionId 内容:vm4l0w033cdng5mevz5bkzzq 路径:/发送:任何类型的连接过期:结束会话的

我无法使用编程完成免责声明部分,但我想如果我手动签署免责声明,我可以将 cookie 的详细信息输入到我的代码中并直接连接到数据页面。我尝试使用下面的代码来执行此操作,但它只返回免责声明页面的 html,这往往意味着它没有使用我给它的 cookie 数据。我究竟做错了什么?

procedure TfmMain.GetWebpageData;
var
  http: TIdHTTP;
  cookie: TIdCookieManager;
  sResponse: String;
begin
  try
    http := TIdHTTP.Create(nil);
    http.AllowCookies := True;
    http.HandleRedirects := True;
    cookie := TIdCookieManager.Create(nil);
    cookie.AddCookie('ASP.NET_SessionId=vm4l0w033cdng5mevz5bkzzq', 'inventory.data.xyz.com');
    http.CookieManager := cookie;

    sResponse := http.Get('http://inventory.data.xyz.com/provide_data.aspx?ID=41100&Mixed=no?fc=true&lang=en');
    ShowMessage(sResponse);  // returns text of disclaimer
  except

  end;
end;
4

1 回答 1

2

由于您没有提供真实的 URL,我只能推测,但很可能您提供的 cookie 值是错误的或在尝试使用它TIdCookieManager时已过时,或者更有可能是完全拒绝 cookie(如果事件未触发,则 cookie 未被接受)。TIdHTTP.Get()TIdCookieManager.AddCookie()TIdCookieManager.OnNewCookie

于 2012-07-01T02:44:23.377 回答