📄 auhttp.int
字号:
FOnBeforeCreateFile, FOnAfterCreateFile: TNotifyEvent;
{$ENDIF}
// internal variables
FBusy, FRealBusy: Boolean;
FThread: TauCustomThread;
HTTPStream: TStream;
HTTPSuccess, HTTPTryAgain, HTTPOutputToFile,
HTTPContinueDownload, HTTPDeleteOutputFileOnAbort: Boolean;
HTTPData: Pointer; // read buffer
HTTPFileSize, HTTPBytesTransferred, HTTPStartTime,
HTTPInitStartRange, HTTPInitEndRange: Cardinal;
{$IFNDEF IE3}
HTTPUploadRequestHeader: String;
{$ENDIF}
// WinInet handles
hSession, hConnect, hRequest: hInternet;
hFile: hFile;
procedure SetAddHeaders(Value: TStrings);
function GetSuspended: Boolean;
procedure SetSuspended(Value: Boolean);
function GetThreadPriority: TThreadPriority;
procedure SetThreadPriority(Value: TThreadPriority);
function GetWaitThread: Boolean;
procedure SetWaitThread(Value: Boolean);
function GetWaitTimeout: Integer;
procedure SetWaitTimeout(Value: Integer);
function GetThreadBusy: Boolean;
function GetFreeOnTerminate: Boolean;
procedure SetFreeOnTerminate(Value: Boolean);
function GetFileName: String;
function GetHostName: String;
function IsNotDefaultAcceptTypes: Boolean;
procedure PrepareProgressParams;
procedure CloseHTTPHandles;
procedure AbortAndReleaseStreams;
// thread management
procedure ThreadExecute(Sender: TObject);
procedure ThreadException(Sender: TObject);
procedure ThreadDone(Sender: TObject);
procedure ThreadWaitTimeoutExpired(Sender: TObject; var TerminateThread: Boolean);
// synchronized methods
procedure CallAborted;
procedure CallHeaderInfo;
procedure CallProgress;
{$IFNDEF IE3}
procedure CallUploadProgress;
{$ENDIF}
procedure CallPasswordRequest;
procedure CallProxyAuthenticationRequest;
{$IFDEF USEINTERNAL}
procedure CallBeforeCreateFile;
procedure CallAfterCreateFile;
{$ENDIF}
protected
// headers
HTTPRawHeadersCRLF, HTTPContentType,
HTTPContentLanguage, HTTPContentEncoding, HTTPLocation, HTTPETag: String;
HTTPDate, HTTPLastModified, HTTPExpires: TDateTime;
// for OnProgres/OnUploadProgress events
ProgressPercentsDone: Byte;
ProgressElapsedTime, ProgressEstimatedTime: Cardinal;
ProgressTransferRate: Single;
procedure DoAnyError;
procedure ReleaseHTTPStream;
public
HTTPErrorCode: Integer;
constructor Create(aOwner: TComponent); override;
destructor Destroy; override;
// public methods
function Read{$IFDEF D4}(ForceWaitThread: Boolean = False){$ENDIF}: Boolean;
function ReadRange(StartRange: Cardinal; EndRange: Cardinal {$IFDEF D4} = 0; ForceWaitThread: Boolean = False{$ENDIF}): Boolean;
{$IFNDEF IE3}
function Upload(NumberOfFields: Word): Boolean;
function BeginPrepareUpload: Boolean;
procedure UploadStream(const FieldName: String; UploadStream: TStream; const FileName: String {$IFDEF D4} = '' {$ENDIF});
procedure UploadString(const FieldName, StrValue: String);
procedure UploadInteger(const FieldName: String; IntValue: Integer);
procedure UploadBoolean(const FieldName: String; BoolValue: Boolean);
procedure UploadPicture(const FieldName: String; Picture: TPicture;
const FileName: String {$IFDEF D4} = S_PIC {$ENDIF});
{$IFDEF USEJPEG}
procedure UploadThumbnailedPicture(const FieldName: String; Picture: TPicture;
ThumbnailWidth: Word {$IFDEF D4} = DefThumbnailWidth {$ENDIF};
ThumbnailHeight: Word {$IFDEF D4} = DefThumbnailHeight {$ENDIF};
JPEGCompressionQuality: Byte {$IFDEF D4} = 90 {$ENDIF};
WriteNormalImageIfThumbnailHaveBiggerSize: Boolean {$IFDEF D4} = True {$ENDIF};
const FileName: String {$IFDEF D4} = S_PIC {$ENDIF});
{$ENDIF}
procedure EndPrepareUpload;
{$ENDIF}
procedure Abort(DeleteOutputFile: Boolean {$IFDEF D4} = False {$ENDIF}; HardTerminate: Boolean {$IFDEF D4} = False {$ENDIF});
// new methods (AppControls v3.6.1)
// works only for binary files. OutputFileName MUST BE SPECIFIED!!
procedure Pause; // same as Abort(False)
function Resume: Boolean;
function IsGlobalOffline: Boolean;
// from TacLoginComponent
property Username: String read FLoginUsername write FLoginUsername stored False;
property Password: String read FLoginPassword write FLoginPassword stored False;
// optional properties
property Busy: Boolean read FBusy;
property ThreadBusy: Boolean read GetThreadBusy;
property FreeOnTerminate: Boolean read GetFreeOnTerminate write SetFreeOnTerminate;
property FileName: String read GetFileName;
property HostName: String read GetHostName;
property Thread: TauCustomThread read FThread;
// public properties
property AcceptTypes: String read FAcceptTypes write FAcceptTypes stored IsNotDefaultAcceptTypes;
property AddHeaders: TStrings read FAddHeaders write SetAddHeaders;
property Agent: String read FAgent write FAgent;
property Proxy: TauHTTPProxy read FProxy write FProxy;
property ShowGoOnlineMessage: Boolean read FShowGoOnlineMessage write FShowGoOnlineMessage default False;
property CacheOptions: TauCacheOptions read FCacheOptions write FCacheOptions default [coReloadIfNoExpireInformation, coReloadUpdatedObjects, coCreateTempFilesIfCantCache];
property InternetOptions: TauInternetOptions read FInternetOptions write FInternetOptions default [ioKeepConnection];
property OutputFileName: String read FOutputFileName write FOutputFileName;
property OutputFileAttributes: TauOutputFileAttributes read FOutputFileAttributes write FOutputFileAttributes;
property URL: String read FURL write FURL;
property POSTData: String read FPOSTData write FPOSTData;
property Range: TauHTTPRange read FRange write FRange;
property Referer: String read FReferer write FReferer;
property RequestMethod: TauHTTPRequestMethod read FRequestMethod write FRequestMethod default rmAutoDetect;
property Timeouts: TauHTTPTimeouts read FTimeouts write FTimeouts;
property TransferBufferSize: TauBufferSize read FTransferBufferSize write FTransferBufferSize default DEF_TRANSFERBUFFERSIZE; // 4Kb
property WorkOffline: Boolean read FWorkOffline write FWorkOffline default False;
property Data: Pointer read FData write FData stored False;
// thread properties
property Suspended: Boolean read GetSuspended write SetSuspended;
property ThreadPriority: TThreadPriority read GetThreadPriority write SetThreadPriority default tpNormal;
property WaitThread: Boolean read GetWaitThread write SetWaitThread default False;
property WaitTimeout: Integer read GetWaitTimeout write SetWaitTimeout default 0;
// public events
property OnBeforeSendRequest: TauHTTPBeforeSendRequest read FOnBeforeSendRequest write FOnBeforeSendRequest;
property OnHeaderInfo: TauHTTPHeaderInfoEvent read FOnHeaderInfo write FOnHeaderInfo;
property OnDone: TauHTTPDoneEvent read FOnDone write FOnDone;
property OnProgress: TauHTTPProgressEvent read FOnProgress write FOnProgress;
property OnStatusChanged: TauHTTPStatusChanged read FOnStatusChanged write FOnStatusChanged;
property OnRedirected: TauHTTPRedirected read FOnRedirected write FOnRedirected;
{$IFNDEF IE3}
property OnUploadProgress: TauHTTPUploadProgressEvent read FOnUploadProgress write FOnUploadProgress;
property OnUploadFieldRequest: TauHTTPUploadFieldRequest read FOnUploadFieldRequest write FOnUploadFieldRequest;
{$ENDIF}
property OnAnyError: TNotifyEvent read FOnAnyError write FOnAnyError;
property OnAborted: TNotifyEvent read FOnAborted write FOnAborted;
property OnConnLost: TauHTTPConnLostEvent read FOnConnLost write FOnConnLost;
property OnDoneInterrupted: TNotifyEvent read FOnDoneInterrupted write FOnDoneInterrupted;
property OnOutputFileError: TNotifyEvent read FOnOutputFileError write FOnOutputFileError;
property OnPasswordRequest: TauHTTPPasswordRequestEvent read FOnPasswordRequest write FOnPasswordRequest;
property OnProxyAuthenticationRequest: TauHTTPProxyAuthenticationEvent read FOnProxyAuthenticationRequest write FOnProxyAuthenticationRequest;
property OnHostUnreachable: TNotifyEvent read FOnHostUnreachable write FOnHostUnreachable;
property OnHTTPError: TauHTTPErrorEvent read FOnHTTPError write FOnHTTPError;
property OnWaitTimeoutExpired: TauThreadWaitTimeoutExpired read FOnWaitTimeoutExpired write FOnWaitTimeoutExpired;
// internal events
{$IFDEF USEINTERNAL}
property OnBeforeCreateFile: TNotifyEvent read FOnBeforeCreateFile write FOnBeforeCreateFile;
property OnAfterCreateFile: TNotifyEvent read FOnAfterCreateFile write FOnAfterCreateFile;
{$ENDIF}
end;
// TauHTTPPragmaNoCache
TauHTTPPragmaNoCache = class(TauCustomHTTP)
public
constructor Create(aOwner: TComponent); override;
property CacheOptions default [coReloadIfNoExpireInformation, coReloadUpdatedObjects, coPragmaNoCache];
end;
// TauHTTP
TauHTTP = class(TauCustomHTTP)
published
property AcceptTypes;
property AddHeaders;
property Agent;
property Proxy;
property URL;
property Username;
property CacheOptions;
property InternetOptions;
property OutputFileName;
property OutputFileAttributes;
property Password;
property POSTData;
property Range;
property Referer;
property RequestMethod;
property ShowGoOnlineMessage;
{$IFDEF USEINTERNAL}
property Suspended;
{$ENDIF}
property Timeouts;
property ThreadPriority;
property TransferBufferSize;
property WaitThread;
property WaitTimeout;
property WorkOffline;
// success
property OnBeforeSendRequest;
property OnHeaderInfo;
property OnDone;
property OnDoneInterrupted;
property OnOutputFileError;
property OnProgress;
{$IFDEF USEINTERNAL}
property OnStatusChanged;
{$ENDIF}
property OnRedirected;
{$IFNDEF IE3}
property OnUploadProgress;
property OnUploadFieldRequest;
{$ENDIF}
// errors
property OnAnyError;
property OnAborted;
property OnConnLost;
property OnHTTPError;
property OnHostUnreachable;
property OnPasswordRequest;
property OnProxyAuthenticationRequest;
property OnWaitTimeoutExpired;
end;
function HTTPReadString(const URL: String; Timeout: Integer {$IFDEF D4} = 0 {$ENDIF}): String;
{ Encodes the string in manner how the address visible in the browser line
(Turns unsafe characters to escape codes) }
function URLEncode(const Str: String): String;
{ Decodes the string from manner how the address visible in the browser line to a normal string
(Unescapes all codes and turns them to normal characters) }
function URLDecode(Str: String): String;
function ParseURL(URL: String; var Protocol, HostName, URLPath,
Username, Password, ExtraInfo: String; var Port: Word): Boolean;
implementation
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -