libpascurl
1.0.0
それは、カールライブラリ周辺のデルファイとオブジェクトのパスカルバインディングとラッパーです。 libcurlは、http、https、ftp、ftps、gopher、tftp、scp、sftp、smb、telnet、dict、ldap、ldap、file、imap、smtp、rtsp、rtsp、rtmpをサポートし、URL構文で指定されたデータを転送するために使用しているライブラリです。
ライブラリがテストされています
ソースを取得し、ソースディレクトリをプロジェクト検索パスに追加します。 FPCの場合、ソースディレクトリをFPC.CFGファイルに追加します。
リポジトリgit clone https://github.com/isemenkov/libpascurlクローンします。
使用するユニットをuses句に追加します。
libpascurl.pasファイルには、Pascalプログラムでこのライブラリを使用するCurl翻訳されたヘッダーが含まれています。 CAPIドキュメントはCurl Webサイトで見つけることができます。
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 | Curl Libraryを初期化し、エラー処理機能を提供するのは基本クラスです。 |
| tsession | これは、サポートされているすべてのプロトコルのセッションの親クラスです。保存されたダウンロード/アップロードデータのためのTmeMoryBufferを提供します。 |
| tresponse | サーバー応答データの親クラスです。 |
| 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認証オプションを設定するためのプロパティを提供します。 |
| tmoduleproxy | クラスは、プロキシオプションをセットアップするプロパティを提供します。 |
| tmodulesock5 | クラスは、SOCK5プロキシオプションをセットアップするプロパティを提供します。 |
| モジュールクラス | 説明 |
|---|---|
| tmodulecontent | クラスは、コンテンツデータバッファを取得するためのプロパティを提供します。 |
| tmoduleheader | クラスは、応答ヘッダーにプロパティを提供します。 HTTPのようなプロトコル-HTTP(S)、FTP(S)、POP3(S)、IMAP、SMTPでのみ使用できます。 |
| tmoduleRedirect | クラスは、リクエストリダイレクトに関する情報を提供します。 |
| tmodulespeed | クラスは、速度ダウンロード/アップロード情報を提供します。 |
| tmoduletimeout | クラスはタイムアウト情報を提供します。 |
| tmoduleinfo | クラスはセッション情報を提供します。 |
ThttpsessionとThttpreSponseクラスは、HTTP(s)プロトコルに関するラッパーを実装します。このクラスは、基本クラスの機能を拡張し、このプロトコルのみに特有の新しいクラスを提供します。
このラッパーは、次のメインモジュールを使用または拡張します。
| セッションモジュール | 応答モジュール |
|---|---|
| tmoduledns | tmodulecontent |
| tmoduleheader | tmoduleheader |
| tmoduleoptions | tmoduleRedirect |
| tmoduleprotocols | tmodulespeed |
| tmodulesocket | tmoduletimeout |
| tmoduletcp | tmoduleinfo |
| tmodulewriter | |
| tmodulereader | |
| tmodulerequest | |
| tmoduleauth | |
| tmoduletlsauth | |
| tmoduleproxy | |
| tmodulesock5 |
| モジュールクラス | 説明 |
|---|---|
| tmoduleRedirect | クラスは、HTTPのリダイレクトオプションをセットアップするプロパティを提供します。 |
| tmodulehttp2 | クラスは、HTTP/2プロトコルオプションをセットアップするプロパティを提供します。 |
| tmoduletimeout | クラスは、HTTP(s)プロトコルタイムアウトオプションをセットアップするプロパティを提供します。 |
| モジュールクラス | 説明 |
|---|---|
| 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 ;