呵呵,这是一个申请免费邮箱的程序,服务商的地址已经被改了 [
]
Delphi 6 + Indy 8
procedure TForm1.MailBox(Acc: String);
var
S: String;
Source: TStrings;
Response: TStringStream;
J: Integer;
Cookie: String;
begin
Response := TStringStream.Create('');
Source := TStringList.Create;
try
while (True) do
begin
// 取第一个页面
S := http.Get('http://reg.qqq.com/qqq.shtml');
Source.Clear;
Source.Add('share=&username=' + Acc);
try
http.post('http://reg.qqq.com/Register.jsp', Source, Response);
except
end;
// 从返回的页面中找出cookie, 并增加到http的extraheaders中
for J := 0 to http.Response.ExtraHeaders.Count - 1 do
begin
if UpperCase(Copy(http.Response.ExtraHeaders[J], 1, 10)) = 'SET-COOKIE' then
begin
Cookie := Trim(Copy(http.Response.ExtraHeaders[J], 12, MAXINT));
Cookie := Copy(Cookie, 1, Pos(';', Cookie) - 1);
http.Request.Extraheaders.Add('Cookie: ' + Cookie);
end;
end;
// 提交用户名,密码,包括前面的cookie等
Source.Clear;
Source.Add('username=' + Acc + '&password=ttt&confirmPassword=ttt');
try
http.Post('http://reg.qqq.com/Register2.jsp', Source, Response);
except
end;
// 删除cookie
while (http.Request.Extraheaders.Count > 2) do
http.request.Extraheaders.Delete(http.Request.Extraheaders.Count - 1);
// 看看有没有成功,呵呵
s := response.DataString;
if Pos('你已经注册成功! ', S) <> 0 then break;
end;
finally
Source.Free;
Response.Free;
end;
end;