• <td id="ae6ms"><li id="ae6ms"></li></td>
  • <xmp id="ae6ms"><td id="ae6ms"></td><table id="ae6ms"></table>
  • <table id="ae6ms"></table>
  • <td id="ae6ms"></td>
    <td id="ae6ms"></td>
  • <table id="ae6ms"></table><table id="ae6ms"><td id="ae6ms"></td></table>
  • <td id="ae6ms"></td>
  • <table id="ae6ms"><li id="ae6ms"></li></table>
  • <table id="ae6ms"></table>
    西西軟件園多重安全檢測下載網站、值得信賴的軟件下載站!
    軟件
    軟件
    文章
    搜索

    首頁編程開發Delphi → delphi7中使用idhttp接收與提交cookie可能會碰到的問題

    delphi7中使用idhttp接收與提交cookie可能會碰到的問題

    前往專題相關軟件相關文章發表評論 來源:本站整理時間:2010/7/25 10:26:57字體大?。?em class="fontsize">A-A+

    作者:佚名點擊:782次評論:0次標簽: cookie

    • 類型:站長工具大?。?i>5KB語言:中文 評分:7.5
    • 標簽:
    立即下載

    下面是簡單的介紹:

    首先在

    (通過idHttp的CookieManager),剩下的 你就專心實現你要完成

    的東西就可以啦。

    不知道你玩過KOK沒有,下面的代碼是登陸KOK注冊頁面的部分代碼:

    unit Unit1;

    interface

    uses

    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

    Dialogs, StdCtrls, ExtCtrls, IdCookieManager, IdBaseComponent,

    IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;

    type

    TForm1 = class(TForm)

    http: TIdHTTP;

    CookieMngr: TIdCookieManager;

    edtUserName: TLabeledEdit;

    edtPassword: TLabeledEdit;

    btnLogin: TButton;

    Cookies: TMemo;

    Memo1: TMemo;

    btnInfor: TButton;

    Button1: TButton;

    edtSN: TLabeledEdit;

    procedure btnLoginClick(Sender: TObject);

    procedure btnInforClick(Sender: TObject);

    private

    { Private declarations }

    public

    { Public declarations }

    end;

    var

    Form1: TForm1;

    implementation

    {$R *.dfm}

    //這個函數是登陸頁面,

    procedure TForm1.btnLoginClick(Sender: TObject);

    var

    s, s1: TStringStream;

    i: Integer;

    begin

    s := TStringStream.Create('');

    s1 := TStringStream.Create('');

    try

    //{

    s.WriteString('action=LOGIN&gameSelect=gkk&');

    s.WriteString('acct=' + edtUserName.Text + '&');

    s.WriteString('pwd=' + edtPassword.Text);

    http.Request.ContentType := 'application/x-www-form-urlencoded';

    try

    http.

    except

    http.Get(http.Response.Location, s1);

    end;

    //}

    Memo1.Lines.Text := s1.DataString;

    //下面的是顯示cookies信息的代碼

    Cookies.Clear;

    for i := 0 to CookieMngr.CookieCollection.Count - 1 do

    Cookies.Lines.Add(CookieMngr.CookieCollection.Items[i].CookieText);

    finally

    s.Free;

    s1.Free;

    end;

    end;

    //這是KOK注冊頁面中,顯示帳戶信息的函數

    procedure TForm1.btnInforClick(Sender: TObject);

    var

    s, s1: TStringStream;

    i: Integer;

    begin

    {

    <form action=../servlet/walletServlet method=post>

    <input type=submit value="修改個人資料">

    <input type=hidden

    </form>

    }

    s := TStringStream.Create('');

    s1 := TStringStream.Create('');

    try

    s.WriteString('action=INFO');

    http.Request.ContentType := 'application/x-www-form-urlencoded';

    try

    http.Post('http://register.kok.com.cn/billing/servlet/walletServlet', s, s1)

    except

    http.Get(http.Response.Location, s1);

    end;

    Memo1.Lines.Text := s1.DataString;

    Cookies.Clear;

    for i := 0 to CookieMngr.CookieCollection.Count - 1 do

    Cookies.Lines.Add(CookieMngr.CookieCollection.Items[i].CookieText);

    finally

    s.Free;

    s1.Free;

    end;

    end;

    end.

    --------------------------------------------------------------------------------

    procedure TForm1.Button1Click(Sender: TObject);

    const

    DFW_LOGIN_URL = 'http://www.delphibbs.com/delphibbs/chkuser.asp';

    UserName = '你的用戶名';

    Password = '你的密碼'; //暈,剛才把密碼寫出來了,得改一下了

    var

    Params: TStrings;

    HTML: String;

    begin

    Params:=TStringList.Create;

    try

    Params.Add('URL='+'/delphibbs/collections.asp');

    //登錄成功后跳轉到的URL,這里直接轉到"我收藏的問題"

    Params.Add('QUERY_STRING='); //登錄成功后跳轉URL的參數

    Params.Add('txtName='+UserName);

    Params.Add('txtPass='+Password);

    //Params.Add('chkSave='); //是否記住我的密碼

    IdHttp.HandleRedirects:=True;

    HTML:=IdHttp.Post(DFW_LOGIN_URL,Params);

    if Pos('<USER Name="" />',HTML)>0 then

    ShowMessage('登錄失??!') //登錄失敗則用戶名為空

    else

    ShowMessage('登錄成功!');

    //分析HTML,取出每一條收藏貼子的URL,下載保存

    finally

    Params.Free;

    end;

    end;

    --------------------------------------------------------------------------------

    搞了幾天,終于有了點眉目,以下是我登錄一個asp站點的delphi程序,使用了IDHttp控件和IDCookieManager控件,在delphi7(帶indy9)+win2k pro調試通過。

    有不當之處請指正,如轉載請注明作者:yannqi。

    1、網站asp程序:

    判斷如果有cookie顯示用戶名和郵件;如果沒有將獲得的用戶名和郵件寫入cookie。

    <%

    if (request.Cookies("name")="" or request.Cookies("email")="") then

    Response.Cookies("name") = request("name")

    Response.Cookies("email") = request("email")

    Response.write(request("name")+","+request("email")+",寫入cookie")

    else

    Response.write("Name:"+request.Cookies("name"))

    Response.write("<br/>email:"+request.Cookies("email"))

    end if

    %>

      相關評論

      閱讀本文后您有什么感想? 已有人給出評價!

      • 8 喜歡喜歡
      • 3 頂
      • 1 難過難過
      • 5 囧
      • 3 圍觀圍觀
      • 2 無聊無聊

      熱門評論

      最新評論

      發表評論 查看所有評論(0)

      昵稱:
      表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
      字數: 0/500 (您的評論需要經過審核才能顯示)
      女人让男人桶30分钟免费视频,女人张开腿让男人桶个爽,一进一出又大又粗爽视频
    • <td id="ae6ms"><li id="ae6ms"></li></td>
    • <xmp id="ae6ms"><td id="ae6ms"></td><table id="ae6ms"></table>
    • <table id="ae6ms"></table>
    • <td id="ae6ms"></td>
      <td id="ae6ms"></td>
    • <table id="ae6ms"></table><table id="ae6ms"><td id="ae6ms"></td></table>
    • <td id="ae6ms"></td>
    • <table id="ae6ms"><li id="ae6ms"></li></table>
    • <table id="ae6ms"></table>