主要代码,我这是跟数据库联接的东西(做得太早,编码很乱,但是应该能让人看懂)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
DBCtrls, Db, Grids, DBGrids, ADODB, ExtCtrls, StdCtrls, NMURL, ScktComp;
type
TForm1 = class(TForm)
ADOQuery1: TADOQuery;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
DBNavigator1: TDBNavigator;
Edit1: TEdit;
Label1: TLabel;
Edit2: TEdit;
Label2: TLabel;
Button1: TButton;
url: TNMURL;
Memo1: TMemo;
ClientSocket1: TClientSocket;
Edit3: TEdit;
Label3: TLabel;
Button2: TButton;
Edit4: TEdit;
Label4: TLabel;
ComboBox1: TComboBox;
Label5: TLabel;
ComboBox2: TComboBox;
Edit5: TEdit;
Label6: TLabel;
Edit6: TEdit;
Label7: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
procedure ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
adoquery1.close;
adoquery1.ConnectionString:='Provider=MSDASQL.1;Persist Security Info=True;Data Source='+edit4.text;
adoquery1.SQL.Text :='select * from 文章 where 日期>=#'+edit1.text+'# and 日期<=#'+edit2.text+'#';
adoquery1.Open;
end;
procedure TForm1.FormCreate(Sender: TObject);
var ttt:textfile;a,b:string;
begin
edit1.text:=datetostr(date());
edit2.text:=edit1.text;
assignfile(ttt,'栏目分类.txt');
reset(ttt);
while not eof(ttt) do
begin
readln(ttt,a);
readln(ttt,b);
combobox1.Items.Add (b);
combobox2.items.add(a);
end;
combobox1.ItemIndex :=8;
combobox2.ItemIndex :=8;
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
combobox2.itemindex:=combobox1.ItemIndex ;
end;
procedure TForm1.ComboBox2Change(Sender: TObject);
begin
combobox1.itemindex:=combobox2.ItemIndex ;
end;
procedure TForm1.Button2Click(Sender: TObject);
var sends,sendp:string;
begin
adoquery1.First;
clientsocket1.active:=true;
end;
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var s:string;
begin
s:=socket.ReceiveText;
if pos('成功',s)<>0 then
begin
clientsocket1.Active :=false;
memo1.Lines.Add('成功');
adoquery1.moveby(1);
clientsocket1.active:=true;
end;
end;
//这里是核心
procedure TForm1.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
var s,sendp,sends:string;
begin
if not adoquery1.Eof then
begin
sends:='POST /regurl/regform.asp HTTP/1.1'+#13#10;
sends:=sends+'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*'+#13#10;
sends:=sends+'Accept-Language: zh-cn'+#13#10;
sends:=sends+'Content-Type: application/x-www-form-urlencoded'+#13#10;
sends:=sends+'Accept-Encoding: gzip, deflate'+#13#10;
sends:=sends+'User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'+#13#10;
sends:=sends+'Host: db.sohu.com'+#13#10;
url.InputString := combobox2.Text;
sendp:='Step=Create&ClassKey='+url.Encode ;
url.inputstring := adoquery1.fieldvalues['文章名']+' 发布者:'+ adoquery1.fieldvalues['作者'] ;
sendp:=sendp+'&SiteName='+url.Encode;
url.inputstring:=edit5.text+'?id='+inttostr(adoquery1.fieldvalues['id']) ;
sendp:=sendp+'&URL='+url.Encode;
url.inputstring:= edit6.text;
sendp:=sendp+'&Description='+url.Encode;
sendp:=sendp+'&Keywords=';
url.inputstring:= edit3.text;
sendp:=sendp+'&EffDate=&ExpDate=&Contact=&EMail='+url.Encode+'&B1=%B5%DD%BD%BB';
sends:=sends+'Content-Length: '+inttostr(length(sendp))+#13#10;
sends:=sends+'Connection: Keep-Alive'+#13+#10+#13#10 +sendp;
memo1.Lines.Add(sends);
clientsocket1.Socket.SendText(sends);
end;
end;
procedure TForm1.ClientSocket1Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
memo1.Lines.Add('连接出错');
errorcode:=0;
end;
end.