Delphi TidHttp登录帖子不起作用?

时间:2018-03-13 12:57:20

标签: delphi idhttp

我正在尝试登录到具有以下授权编码的网站。我的应用程序是带有def check (self , request): if unique('username' , 'email'): return True return False TIdHTTPTIdSSLIOHandlerSocketOpenSSL组件的RAD Studio 10.2 Tokyo FireMonkey应用程序。

我将帖子的回复返回到TWebBrowser,但我只是从帖子中返回登录页面。我尝试登录的网站是:https://admin.salestaxonline.com/default_sto.aspx

我使用的是正确的用户名和密码。为什么我似乎没有登录?

以下是登录页面中的相关条目:

TWebBrowser

以下是代码(已更正以显示所有相关行):

div id="pnlLogin" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'cmdLogin2')"
input name="UN" type="text" id="UN" class="form-control"
input name="PW" type="password" id="PW" class="form-control" autocomplete="off"
input type="submit" name="cmdLogin2" value="Login" id="cmdLogin2" class="btn btn-md btn-default btn-block"

我使用Fidder从浏览器访问帖子请求:

procedure LoginToSite(AUrl,AUsername,APassword: String);
var
  Request: TStringList;
  ResponseText: String;
begin
  try
    Request := TStringList.Create;
    try
        ResponseText := IdHttp.Get(AUrl);
        Request.Add('UN='+AUsername);
        Request.Add('PW='+APassword);
        Request.Add('CmdLogin2=Login');
        IdHttp.Request.Connection := 'keep-alive';
        IdHttp.Request.UserAgent := 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0';
        IdHttp.AllowCookies := True;
        IdHttp.HandleRedirects := True;
        ResponseText := IdHttp.Post(AUrl,Request);
        WB.LoadFromStrings(ResponseText,'http://www.google.com');
      finally
        Request.Free;
      end;
    except
      on E: Exception do
        LogMessage(E.Message);
    end;
  end;

0 个答案:

没有答案