libpascurl
1.0.0
它是Delphi和Object Pascal Bindings和Curl庫周圍的包裝器。 libcurl是圖書館用於傳輸用URL語法指定的數據,支持HTTP,HTTP,FTP,FTP,FTP,Gopher,Gopher,TFTP,SCP,SFTP,SFTP,SFTP,SMB,SMB,TELNET,dict,dict,ldap,ldap,ldap,ldaps,file,file,file,imap,imap,smtp,pop3,pop3,rtsp和rtsp和rtmp和rtmp和rtmp。
圖書館已測試
獲取來源並將源目錄添加到項目搜索路徑中。對於FPC,將源目錄添加到fpc.cfg文件中。
克隆存儲庫git clone https://github.com/isemenkov/libpascurl 。
將要使用的單元添加到uses條款中。
libpascurl.pas文件包含在Pascal程序中使用此庫的捲曲翻譯標頭。您可以在Curl網站上找到C API文檔。
uses
libpascurl;
var
handle : CURL;
effectiveUrl, contentType, ip : PChar;
responseCode, headerSize : Longint;
contentLength, totalTime : Longword;
buffer : TStringStream;
function WriteFunctionCallback (ptr : PChar; size : LongWord;
nmemb : LongWord; data : Pointer)
begin
buffer.WriteString(string(ptr));
end ;
begin
curl_global_init(CURL_GLOBAL_ALL);
curl_easy_setopt(handle, CURLOPT_URL, PChar( ' https://example.dev ' );
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, @WriteFunctionCallback);
buffer := TStringStream.Create( ' ' );
if curl_easy_perform = CURLE_OK then
begin
New(effectiveUrl);
New(contentType);
New(ip);
curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, @effectiveUrl);
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, @responseCode);
curl_easy_getinfo(handle, CURLINFO_HEADER_SIZE, @headerSize);
curl_easy_getinfo(handle, CURLINFO_CONTENT_TYPE, @contentType);
curl_easy_getinfo(handle, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, @contentLength);
curl_easy_getinfo(handle, CURLINFO_LOCAL_IP, @ip);
curl_easy_getinfo(handle, CURLINFO_TOTAL_TIME_T, @totalTime);
writeln( ' URL: ' : 20 , effectiveUrl);
writeln( ' Response code: ' : 20 , responseCode);
writeln( ' Header size, kB: ' : 20 , FormatFloat( ' 0.00 ' , headerSize / 1024 ));
writeln( ' Content type: ' , contentType);
writeln( ' Content length, kB: ' : 20 , FormatFloat( ' 0.00 ' , contentLength / 1024 ));
writeln( ' IP: ' : 20 , ip);
writeln( ' Total time, ms: ' : 20 , totalTime);
writeln( ' ==== Content ==== ' );
writeln(buffer.DataString);
end ;
curl_global_cleanup;
end ;該庫包含一組類,用於在受支持的協議周圍創建高級包裝器。 source/curl/文件夾包含實現特定功能的基本組件。
| 班級 | 描述 |
|---|---|
| tcurleasy | 它是初始化捲曲庫並提供錯誤處理功能的基類。 |
| tsession | 它是所有受支持協議的會話的父類。它提供了用於存儲下載/上傳數據的TmemoryBuffer。 |
| 特雷斯頓 | 它是服務器響應數據的父類。 |
| tpropertymodule | 它是所有會話和響應的基類其他功能模塊。 |
| 模塊類 | 描述 |
|---|---|
| tmoduledns | 類為設置LIBCURL DNS選項提供屬性。 |
| tmodulerequest | 類為設置請求屬性和回調提供屬性。 |
| tmoduleheader | 課程為設置標頭提供屬性。只能與HTTP樣協議一起使用-HTTP(S),FTP(S),POP3(S),IMAP,SMTP。 |
| tmoduleOptions | 課程為設置不同的Libcurl內部選項提供屬性。 |
| Tmoduleprotocols | 類提供設置LIBCURL協議選項的屬性。 |
| tmodulesocket | 類向套接字設置提供屬性。 |
| tmoduletCP | 類為設置TCP協議選項提供屬性。 |
| tmodulewriter | 類提供設置下載回調功能的屬性。 |
| tmodulereader | 類提供設置上傳回調函數的屬性。 |
| tmoduleauth | 類為設置驗證選項提供屬性。 |
| tmoduletlsauth | 類為設置TLS auth身份驗證選項提供屬性。 |
| tmoduleproxy | 類為設置代理選項提供屬性。 |
| tmodulesock5 | 類為設置Sock5代理選項提供屬性。 |
| 模塊類 | 描述 |
|---|---|
| tmodulecontent | 類提供屬性以獲取內容數據緩衝區。 |
| tmoduleheader | 課程為響應標頭提供屬性。只能與HTTP樣協議一起使用-HTTP(S),FTP(S),POP3(S),IMAP,SMTP。 |
| Tmoduleredirect | 課程提供有關請求重定向的信息。 |
| tmodulaspeed | 課程提供速度下載/上傳信息。 |
| tmoduletimeout | 課程提供超時信息。 |
| tmoduleinfo | 課程提供會話信息。 |
Thttpsession和Thttpresponse類實現了有關HTTP協議的包裝器。該類擴展了基類的功能,並提供了僅針對此協議的新的。
該包裝器使用或擴展了下一個主要模塊:
| 會話模塊 | 響應模塊 |
|---|---|
| ✔️tmoduledns | ✔️tmodulecontent |
| ✔️tmoduleheader | ✔️tmoduleheader |
| ✔️tmoduleOptions | ✔️tmoduleredirect |
| ✔️tmoduleprotocols | ✔️tmodulaspeed |
| ✔️tmodulesocket | ✔️tmoduletimeout |
| ✔️tmoduletcp | ✔️tmoduleinfo |
| ✔️tmodulewriter | |
| ✔️tmodulereader | |
| ✔️tmodulerequest | |
| ✔️tmoduleauth | |
| ✔️tmoduletlsauth | |
| ✔️tmoduleproxy | |
| ✔️tmodulesock5 |
| 模塊類 | 描述 |
|---|---|
| Tmoduleredirect | 類為設置HTTP(S)重定向選項提供屬性。 |
| tmodulehttp2 | 類為設置HTTP/2協議選項提供屬性。 |
| tmoduletimeout | 類為設置HTTP協議超時選項提供屬性。 |
| 模塊類 | 描述 |
|---|---|
| tmodulecookie | 課程提供cookie數據。 |
uses
curl.http.session, curl.http.response;
var
Session : THTTP.TSession;
Response : THHTP.TResponse;
begin
Session.Url := ' https://github.com/isemenkov ' ;
Session.Redirect.FollowRedirect := True;
Response := Session.Get;
writeln( ' Url ' , Response.Request.Url);
writeln( ' Response code ' , Response.Header.ResponseCode);
writeln( ' Content-type ' , Response.Content.ContentType);
writeln( ' Content-size ' , Response.Content.ContentSize);
writeln( ' Content ' , Response.Content.ToString);
end ;