destructor THttp.Destroy;
begin
FHttpStr.Free;
FKeys.Free;
FValues.Free;
inherited Destroy;
end;
function THttp.GetItems(Key: String): String;
var
Index : Integer;
begin
Index := FKeys.IndexOf(Key);
if Index = -1 then
Result := ''
else
Result := FValues[Index];
end;
procedure THttp.SetHttp(AHttp: String);
procedure Parser(AStr:String);
begin
FKeys.Add(Copy(AStr,1, Pos(':',AStr) - 1));
FValues.Add( Copy(AStr, Pos(':',AStr) + 1, Length(AStr)));
end;
var
I:Integer;
begin
FHttpStr.Text := AHttp;
FValues.Clear;
FKeys.Clear;
for I := 1 to FHttpStr.Count - 1 do
begin
Parser(FHttpStr);
end;
end;
用法:
var
h : THttp;
begin
h := THttp.Create;
h.SetHttp('GET / HTTP/1.1'
+#13'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, */*'
+#13'Accept-Language: zh-cn'
+#13'Accept-Encoding: gzip, deflate'
+#13'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'
+#13'Host: www.baidu.com'
+#13'Connection: Keep-Alive'
+#13'Cookie: BAIDUID=B6BA1FA1F179216F9F9B108E765DE0BD; PASSPORTRETRYSTRING=1182962306');
ShowMessage('Accept:'+h['Accept']);
ShowMessage('ccept-Language:'+h['Accept-Language']);
ShowMessage('Accept-Encoding:'+h['Accept-Encoding']);
ShowMessage('Host:'+h['Host']);
ShowMessage('Connection:'+h['Connection']);
ShowMessage('Cookie:'+h['Cookie']);
h.Free;
end;