libpascurl
1.0.0
컬 라이브러리 주변의 델파이 및 물체 파스칼 바인딩 및 래퍼입니다. Libcurl은 라이브러리가 URL 구문으로 지정된 데이터를 전송하고 HTTP, HTTPS, FTP, FTPS, Gopher, TFTP, SCP, SFTP, SMB, TELNET, DICT, LDAP, LDAPS, 파일, IMAP, SMTP, POP3, RTSP 및 RTMP를 전송하는 데 사용 중입니다.
도서관이 테스트되었습니다
소스를 가져 와서 소스 디렉토리를 프로젝트 검색 경로에 추가하십시오. FPC의 경우 소스 디렉토리를 FPC.CFG 파일에 추가하십시오.
저장소 git clone https://github.com/isemenkov/libpascurl 복제하십시오.
사용하려는 단위를 uses 절에 추가하십시오.
libpascurl.pas 파일에는 Pascal 프로그램 에서이 라이브러리를 사용하기위한 CURL 번역 헤더가 포함되어 있습니다. 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 | CURL 라이브러리를 초기화하고 오류 처리 기능을 제공하는 기본 클래스입니다. |
| tsession | 지원되는 모든 프로토콜의 세션을위한 부모 클래스입니다. 저장된 다운로드/업로드 데이터를위한 tmemorybuffer를 제공합니다. |
| TREPONSE | 서버 응답 데이터의 부모 클래스입니다. |
| 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 (들) 프로토콜에 대한 래퍼를 구현합니다. 이 클래스는 기본 클래스의 기능을 확장 하고이 프로토콜에만 특정한 새로운 클래스를 제공했습니다.
이 래퍼는 다음 주요 모듈을 사용하거나 확장합니다.
| 세션 모듈 | 응답 모듈 |
|---|---|
| tmoduledns | tmodulecontent |
| ✔️ tmoduleHeader | ✔️ tmoduleHeader |
| tmoduleoptions | tmoduleredirect |
| tmoduleprotocols | tmodulespeed |
| ✔️ tmodulesocket | ✔️ tmoduletimeout |
| ✔️ tmoduletcp | ✔️ tmoduleinfo |
| tmodulewriter | |
| tmodulereader | |
| tmodulerequest | |
| tmoduleauth | |
| tmoduletlsauth | |
| tmoduleproxy | |
| ✔️ tmodulesock5 |
| 모듈 클래스 | 설명 |
|---|---|
| tmoduleredirect | 클래스는 HTTP (S) 리디렉션 옵션을 설정하는 속성을 제공합니다. |
| tmodulehttp2 | 클래스는 HTTP/2 프로토콜 옵션을 설정하는 속성을 제공합니다. |
| tmoduletimeout | 클래스는 HTTP (S) 프로토콜 타임 아웃 옵션을 설정하는 속성을 제공합니다. |
| 모듈 클래스 | 설명 |
|---|---|
| tmodulecookie | 클래스는 쿠키 데이터를 제공합니다. |
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 ;