我想做一个登陆器,模拟 asp 的登陆功能,查了资料是 POST 一个数据到一个 asp 页面,
我参照这些资料用 WinInet 写好了程序,可是POST数据后,再用IE打开,却还是未登陆状态,请问如何解决?一经解决,马上送上分数!

解决方案 »

  1.   

    你POST的是不是有问题,一般session不会马上掉了,尤其在ASP中
      

  2.   

    我的代码如下:procedure TForm1.Button1Click(Sender: TObject);
    const
      aHost = 'www.xxxxxxx.com';
      aURL  = '/user/check.asp';
      aData = 'Content-Type: application/x-www-form-urlencoded';
    var
      hSession: HINTERNET;
      hService: HINTERNET;
      hRequest: HINTERNET;  sData: String;
      Buff: Pointer;
      BuffLen, dwIndex: DWORD;
      aAccept: PChar;
    begin
      lbMsg.Caption := '正在登陆...';
      Update;
      Application.ProcessMessages;  hSession := InternetOpen('Mobile', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
      if hSession = nil then
      begin
        lbMsg.Caption := '重要文件 WinInet.Dll 损坏!';
        Exit;
      end;  hService := InternetConnect(hSession, aHost, INTERNET_DEFAULT_HTTP_PORT, nil, nil,
                                  INTERNET_SERVICE_HTTP, 0,  1);
      if hService = nil then
      begin
        InternetCloseHandle(hSession);
        lbMsg.Caption := 'InternetConnect';
        Exit;
      end;  GetMem(aAccept, 10);
      StrPCopy(aAccept, 'Accept: */*');
      hRequest := HttpOpenRequest(hService, 'POST', aURL, nil, nil, @aAccept,
                                  0, 1);       //INTERNET_FLAG_EXISTING_CONNECT or INTERNET_FLAG_KEEP_CONNECTION
      if hRequest = nil then
      begin
        InternetCloseHandle(hService);
        InternetCloseHandle(hSession);
        lbMsg.Caption := 'HttpOpenRequest';
        Exit;
      end;  sData := Format('username=%s&pass=%s', [ComboBox1.Text, Edit1.Text]);
      if not HttpSendRequest(hRequest, aData, Length(aData), PChar(sData), Length(sData)) then
      begin
        InternetCloseHandle(hRequest);
        InternetCloseHandle(hService);
        InternetCloseHandle(hSession);
        lbMsg.Caption := 'HttpSendRequest';
        Exit;
      end;
      ShellExecute(Handle, 'open', 'http://www.xxxxxxxxx.com/index.asp', nil, nil, SW_SHOW);
      Sleep(1000);  GetMem(Buff, 10);
      FillChar(Buff^, 10, #0);
      BuffLen := 4;
      dwIndex := 0;
      if not HttpQueryInfo(hRequest, HTTP_QUERY_STATUS_CODE or HTTP_QUERY_FLAG_NUMBER, Buff, BuffLen, dwIndex) then
      begin
        InternetCloseHandle(hRequest);
        InternetCloseHandle(hService);
        InternetCloseHandle(hSession);
        lbMsg.Caption := 'HttpQueryInfo';
        Exit;
      end;  lbMsg.Caption := PChar(Buff);
      InternetCloseHandle(hRequest);
      InternetCloseHandle(hService);
      InternetCloseHandle(hSession);
    end;
      

  3.   

    我看写的累的。用browse控件
    两句就差不多了。
      

  4.   

    要看网站,也许网站是用 cookie 的呢?
    用cookie 的,一关浏览器就把 cookie 清了