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 ;