Delphi Indy控制項實現網路驗證與asp通訊

來源:互聯網
上載者:User

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls, ComCtrls, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;

type
TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Label1: TLabel;
    state: TStatusBar;
    IdHTTP1: TIdHTTP;
    Memo1: TMemo;
    Label2: TLabel;
    Edit2: TEdit;
    Button2: TButton;
    Label3: TLabel;
    Memo2: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
private
    { Private declarations }
public
    { Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
name:String;
password:string;

GetURL      :String;
PostURL     :String;
GetHtml     :String;
sParams     :String;
aParams     :TStrings;
aStream     :TStringStream;
begin

IdHTTP1 := TIdHTTP.Create(nil);
aParams := TStringList.Create;
aStream := TStringStream.Create('');
memo1.Lines.Clear ;
name:=edit1.Text ;
password:=edit2.Text ;
GetURL      := 'http://localhost/getinfo.asp'; {登入頁面網址}
PostURL     := 'http://localhost/getinfo.asp?password='+password; {提交網址}
sParams     := 'name='+name; {提交參數}
try
    aParams.Clear;
    aParams.Add(sParams);
    GetHtml := IdHTTP1.Get(GetURL); {取登入頁面}
    IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
    IdHTTP1.Post(PostURL, aParams, aStream); {提交}
    memo1.lines.Add(aStream.DataString);
    memo1.SelectAll ;
finally
    IdHTTP1.Free;
    aParams.Free;
    aStream.Free;
end;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
close();
end;

end.

-----------------------------------------------------GetInfo.asp----------------------------------------

<%@LANGUAGE = VBScript.Encode%>
<!--#include file="conn.asp"-->
<%
dim rs,sql,username,regcode,active,password,founderr,msg
username=trim(request("name"))
password=trim(request("password"))
if username="" then
   founderr=true
   msg="username參數無效!"
else
   founderr=false
end if
if password="" then
   founderr=true
   msg="password參數無效!"
else
   founderr=false
end if

if founderr=true then
   response.write msg
else
   set rs=Server.CreateObject("ADODB.RecordSet")
   sql="select * from reguser where username='"&username&"' and password='"&password&"'"
   rs.open sql,conn,1,1
   if rs.recordcount>0 then
      if trim(rs("regcode"))<>"" then
         response.write rs("regcode")
      else
         response.write "返回的使用者註冊碼無效!"
      end if
   else
      response.write "輸入的使用者名稱不存在或者密碼無效!"
   end if
   rs.close
   set rs=nothing
end if

call closeconn()
%>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.