再谈Delphi XE的System.Net.HttpClientComponent、System.Net.HttpClient、System.Net.URLClient
一、继承关系
System.Net.HttpClientComponent -> TNetHTTPClient.Create(nil);
-> System.Net.HttpClient
System.Net.HttpClient -> THTTPClient.Create;
-> System.Net.URLClient
System.Net.URLClient -> THTTPClient(TURLSchemes.GetURLClientInstance('HTTP'));
-> : TURLClient;
二、TURLClient.Create自动获取默认值
constructor TURLClient.Create;
begin
inherited;
-
FCustomHeaders := [TNetHeader.Create(sUserAgent, DefaultUserAgent)];
-
FInternalCredentialsStorage := TCredentialsStorage.Create;
-
FInstances := TObjectDictionary<string, TURLClient>.Create;
-
FCredentialsStorage := FInternalCredentialsStorage;
-
FConnectionTimeout := DefaultConnectionTimeout;
-
FResponseTimeout := DefaultResponseTimeout;
end;
其中:
-
public const
-
DefaultConnectionTimeout = 60000;
-
DefaultResponseTimeout = 60000;
-----------> System.NetConsts
-
const
-
DefaultUserAgent = 'Embarcadero URI Client/1.0'; // Do not translate
-
// Common Header Names
-
sUserAgent = 'User-Agent'; // Do not translate
-
sAccept = 'Accept'; // Do not translate
-
sAcceptCharset = 'Accept-Charset'; // Do not translate
-
sAcceptEncoding = 'Accept-Encoding'; // Do not translate
-
sAcceptLanguage = 'Accept-Language'; // Do not translate
-
sAcceptRanges = 'Accept-Ranges'; // Do not translate
-
sContentEncoding = 'Content-Encoding'; // Do not translate
-
sContentLanguage = 'Content-Language'; // Do not translate
-
sContentLength = 'Content-Length'; // Do not translate
-
sContentType = 'Content-Type'; // Do not translate
-
sLastModified = 'Last-Modified'; // Do not translate
-
sContentDisposition = 'Content-Disposition'; // Do not translate
-
sLocation = 'Location'; // Do not translate
-
sSetCookie = 'Set-Cookie'; // Do not translate
-
sCookie = 'Cookie'; // Do not translate
-
sRange = 'Range'; // Do not translate
-
sXMethodOverride = 'x-method-override'; // Do not translate
-
sWWWAuthenticate = 'WWW-Authenticate'; // Do not translate
-
sProxyAuthenticate = 'Proxy-Authenticate'; // Do not translate
-
sAuthorization = 'Authorization'; // Do not translate
-
sProxyAuthorization = 'Proxy-Authorization'; // Do not translate
例如 :
-
TNetHTTPClient.ConnectionTimeout := 5000; // 5秒
-
TNetHTTPClient.ResponseTimeout := 10000; // 10秒
-
TNetHTTPClient.AcceptCharSet := 'utf-8';
-
TNetHTTPClient.AcceptEncoding:='65001';
-
TNetHTTPClient.AcceptLanguage:='zh-CN';
-
TNetHTTPClient.ContentType := 'text/html';
-
TNetHTTPClient.UserAgent := 'Embarcadero URI Client/1.0';
三、相关文章:
2、delphi Restful:客户端实现的四种方式及其比较:https://blog.csdn.net/pulledup/article/details/104132753
3、delphi XE应用Restful时Rest组件的delphi XE ContentType即delphi XE mime type怎样获取和表达: