Release 16

git-svn-id: https://svn.code.sf.net/p/synalist/code/trunk@35 7c85be65-684b-0410-a082-b2ed4fbef004
This commit is contained in:
geby
2008-04-24 06:42:13 +00:00
parent 7daa8087a7
commit a68b85e498
4 changed files with 468 additions and 39 deletions

View File

@ -1,7 +1,7 @@
{==============================================================================|
| Project : Delphree - Synapse | 001.001.000 |
| Project : Delphree - Synapse | 001.002.000 |
|==============================================================================|
| Content: HTTP client |
| Content: HTTP client |
|==============================================================================|
| The contents of this file are subject to the Mozilla Public License Ver. 1.0 |
| (the "License"); you may not use this file except in compliance with the |
@ -14,7 +14,7 @@
| The Original Code is Synapse Delphi Library. |
|==============================================================================|
| The Initial Developer of the Original Code is Lukas Gebauer (Czech Republic).|
| Portions created by Lukas Gebauer are Copyright (c) 1999. |
| Portions created by Lukas Gebauer are Copyright (c) 1999,2000,2001. |
| All Rights Reserved. |
|==============================================================================|
| Contributor(s): |
@ -27,7 +27,7 @@ unit HTTPsend;
interface
uses
Blcksock, sysutils, classes, windows, SynaUtil;
Blcksock, sysutils, classes, windows, SynaUtil, SynaCode;
const
CRLF=#13+#10;
@ -39,13 +39,21 @@ type
public
timeout:integer;
HTTPHost:string;
HTTPPort:integer;
HTTPPort:string;
ProxyHost:string;
ProxyPort:string;
ProxyUser:string;
ProxyPass:string;
ResultCode:integer;
Constructor Create;
Destructor Destroy; override;
function Request(Query,Response:TStrings):Boolean;
function DoMethod(method,URL:string;Content,Response:TStrings):boolean;
end;
function get(Host,URI:string;Response:TStrings):Boolean;
function SimpleGet(URL:string;Response:TStrings):Boolean;
function Get(URL:string;Response:TStrings):Boolean;
function Post(URL:string;Value,Response:TStrings):Boolean;
implementation
@ -57,7 +65,11 @@ begin
sock.CreateSocket;
timeout:=300000;
HTTPhost:='localhost';
HTTPPort:=80;
HTTPPort:='80';
ProxyHost:='';
ProxyPort:='8080';
ProxyUser:='';
ProxyPass:='';
end;
{THTTPSend.Destroy}
@ -74,7 +86,7 @@ var
n:integer;
begin
Result:=False;
sock.Connect(HTTPHost,IntToStr(HTTPPort));
sock.Connect(HTTPHost,HTTPPort);
if sock.lasterror<>0 then Exit;
for n:=0 to Query.Count-1 do
Sock.SendString(Query[n]+CRLF);
@ -88,20 +100,84 @@ begin
Result:=True;
end;
{THTTPSend.DoMethod}
function THTTPSend.DoMethod(method,URL:string;Content,Response:TStrings):boolean;
var
Prot,User,Pass,Host,Port,Path,Para:string;
Query:TstringList;
size:integer;
s:string;
begin
result:=false;
Query:=TstringList.create;
try
parseURL(URL,Prot,User,Pass,Host,Port,Path,Para);
if content<>nil
then query.AddStrings(content);
size:=length(query.text);
query.insert(0,'');
query.insert(0,'User-Agent: Synapse/1.1');
query.insert(0,'Connection: close');
query.insert(0,'Accept-Encoding: identity');
if User<>''
then query.insert(0,'Authorization: Basic '+EncodeBase64(user+':'+pass));
if (proxyhost<>'') and (proxyUser<>'')
then query.insert(0,'Proxy-Authorization: Basic '+EncodeBase64(Proxyuser+':'+Proxypass));
if size>0
then query.insert(0,'Content-Length: '+inttostr(size));
query.insert(0,'Host: '+host+':'+port);
if para=''
then s:=''
else s:='?'+para;
s:=path+s;
if proxyHost<>''
then s:=prot+'://'+host+':'+port+s;
query.insert(0,uppercase(method)+' '+s+' HTTP/1.0');
if proxyhost=''
then
begin
HttpHost:=host;
HttpPort:=port;
end
else
begin
HttpHost:=Proxyhost;
HttpPort:=Proxyport;
end;
result:=request(query,response);
ResultCode:=0;
if response.count>0
then if pos('HTTP/',uppercase(response[0]))=1
then
begin
s:=separateright(response[0],' ');
s:=separateleft(s,' ');
ResultCode:=StrToIntDef(s,0);
end;
finally
Query.free;
end;
end;
{==============================================================================}
{get}
function get(Host,URI:string;Response:TStrings):Boolean;
{SimpleGet}
function SimpleGet(URL:string;Response:TStrings):Boolean;
var
HTTP:THTTPSend;
Query:TStringList;
Prot,User,Pass,Host,Port,Path,Para:string;
begin
parseURL(URL,Prot,User,Pass,Host,Port,Path,Para);
if para<>''
then path:=path+'?'+para;
Result:=False;
HTTP:=THTTPSend.Create;
Query:=TStringList.create;
try
HTTP.HTTPhost:=Host;
Query.Add('GET '+URI+' HTTP/0.9');
Query.Add('GET '+Path);
if not HTTP.Request(Query,Response) then Exit;
finally
Query.Free;
@ -110,4 +186,35 @@ begin
Result:=True;
end;
{get}
function Get(URL:string;Response:TStrings):Boolean;
var
HTTP:THTTPSend;
Prot,User,Pass,Host,Port,Path,Para:string;
begin
Result:=False;
HTTP:=THTTPSend.Create;
try
result:=HTTP.DoMethod('GET',URL,nil,Response);
finally
HTTP.Free;
end;
end;
{post}
function Post(URL:string;Value,Response:TStrings):Boolean;
var
HTTP:THTTPSend;
Prot,User,Pass,Host,Port,Path,Para:string;
begin
Result:=False;
HTTP:=THTTPSend.Create;
try
result:=HTTP.DoMethod('POST',URL,Value,Response);
finally
HTTP.Free;
end;
end;
end.