std.net.curl
Note You may need to link to the curl library, e.g. by adding "libs": ["curl"] to your dub.json file if you are using DUB.
Windows x86 note: A DMD compatible libcurl static library can be downloaded from the dlang.org download archive page. Compared to using libcurl directly this module allows simpler client code for common uses, requires no unsafe operations, and integrates better with the rest of the language. Futhermore it provides range access to protocols supported by libcurl both synchronously and asynchronously. A high level and a low level API are available. The high level API is built entirely on top of the low level one. The high level API is for commonly used functionality such as HTTP/FTP get. The byLineAsync and byChunkAsync provides asynchronous range that performs the request in another thread while handling a line/chunk in the current thread. The low level API allows for streaming and other advanced features.| Function Name | Description | 
|---|---|
| High level | |
| download | download("ftp.digitalmars.com/sieve.ds", "/tmp/downloaded-ftp-file") downloads file from URL to file system. | 
| upload | upload("/tmp/downloaded-ftp-file", "ftp.digitalmars.com/sieve.ds"); uploads file from file system to URL. | 
| get | get("dlang.org") returns a char[] containing the dlang.org web page. | 
| put | put("dlang.org", "Hi") returns a char[] containing the dlang.org web page. after a HTTP PUT of "hi" | 
| post | post("dlang.org", "Hi") returns a char[] containing the dlang.org web page. after a HTTP POST of "hi" | 
| byLine | byLine("dlang.org") returns a range of char[] containing the dlang.org web page. | 
| byChunk | byChunk("dlang.org", 10) returns a range of ubyte[10] containing the dlang.org web page. | 
| byLineAsync | byLineAsync("dlang.org") returns a range of char[] containing the dlang.org web page asynchronously. | 
| byChunkAsync | byChunkAsync("dlang.org", 10) returns a range of ubyte[10] containing the dlang.org web page asynchronously. | 
| Low level | |
| HTTP | HTTP struct for advanced usage | 
| FTP | FTP struct for advanced usage | 
| SMTP | SMTP struct for advanced usage | 
Example
import std.net.curl, std.stdio; // Return a char[] containing the content specified by a URL auto content = get("dlang.org"); // Post data and return a char[] containing the content specified by a URL auto content = post("mydomain.com/here.cgi", ["name1" : "value1", "name2" : "value2"]); // Get content of file from ftp server auto content = get("ftp.digitalmars.com/sieve.ds"); // Post and print out content line by line. The request is done in another thread. foreach (line; byLineAsync("dlang.org", "Post data")) writeln(line); // Get using a line range and proxy settings auto client = HTTP(); client.proxy = "1.2.3.4"; foreach (line; byLine("dlang.org", client)) writeln(line);For more control than the high level functions provide, use the low level API:
Example
import std.net.curl, std.stdio; // GET with custom data receivers auto http = HTTP("dlang.org"); http.onReceiveHeader = (in char[] key, in char[] value) { writeln(key, ": ", value); }; http.onReceive = (ubyte[] data) { /+ drop +/ return data.length; }; http.perform();First, an instance of the reference-counted HTTP struct is created. Then the custom delegates are set. These will be called whenever the HTTP instance receives a header and a data buffer, respectively. In this simple example, the headers are written to stdout and the data is ignored. If the request should be stopped before it has finished then return something less than data.length from the onReceive callback. See onReceiveHeader/onReceive for more information. Finally the HTTP request is effected by calling perform(), which is synchronous.
Source std/net/curl.d
Credits The functionally is based on libcurl. LibCurl is licensed under an MIT/X derivative license.
- public import etc.c.curl :CurlOption;
- structAutoProtocol;
- Example - import std.net.curl; // Two requests below will do the same. char[] content; // Explicit connection provided content = get!HTTP("dlang.org"); // Guess connection type by looking at the URL content = get!AutoProtocol("ftp://foo.com/file"); // and since AutoProtocol is default this is the same as content = get("ftp://foo.com/file"); // and will end up detecting FTP from the url and be the same as content = get!FTP("ftp://foo.com/file"); 
- voiddownload(Conn = AutoProtocol)(const(char)[]url, stringsaveToPath, Connconn= Conn())
 if (isCurlConn!Conn);
- HTTP/FTP download to local file system.Parameters:const(char)[] urlresource to download string saveToPathpath to store the downloaded content on local disk Conn connconnection to use e.g. FTP or HTTP. The default AutoProtocol will guess connection type and create a new instance for this call only. Example import std.net.curl; download("https://httpbin.org/get", "/tmp/downloaded-http-file"); 
- voidupload(Conn = AutoProtocol)(stringloadFromPath, const(char)[]url, Connconn= Conn())
 if (isCurlConn!Conn);
- Upload file from local files system using the HTTP or FTP protocol.Parameters:string loadFromPathpath load data from local disk. const(char)[] urlresource to upload to Conn connconnection to use e.g. FTP or HTTP. The default AutoProtocol will guess connection type and create a new instance for this call only. Example import std.net.curl; upload("/tmp/downloaded-ftp-file", "ftp.digitalmars.com/sieve.ds"); upload("/tmp/downloaded-http-file", "https://httpbin.org/post"); 
- T[]get(Conn = AutoProtocol, T = char)(const(char)[]url, Connconn= Conn())
 if (isCurlConn!Conn && (is(T == char) || is(T == ubyte)));
- HTTP/FTP get content.Parameters:const(char)[] urlresource to get Conn connconnection to use e.g. FTP or HTTP. The default AutoProtocol will guess connection type and create a new instance for this call only. The template parameter T specifies the type to return. Possible values are char and ubyte to return char[] or ubyte[]. If asking for char, content will be converted from the connection character set (specified in HTTP response headers or FTP connection properties, both ISO-8859-1 by default) to UTF-8. Example import std.net.curl; auto content = get("https://httpbin.org/get"); Returns:A T[] range containing the content of the resource pointed to by the URL.Throws:CurlException on error.See Also:
- T[]post(T = char, PostUnit)(const(char)[]url, const(PostUnit)[]postData, HTTPconn= HTTP())
 if (is(T == char) || is(T == ubyte));
 T[]post(T = char)(const(char)[]url, string[string]postDict, HTTPconn= HTTP())
 if (is(T == char) || is(T == ubyte));
- HTTP post content.Parameters:const(char)[] urlresource to post to string[string] postDictdata to send as the body of the request. An associative array of string is accepted and will be encoded using www-form-urlencoding const(PostUnit)[] postDatadata to send as the body of the request. An array of an arbitrary type is accepted and will be cast to ubyte[] before sending it. HTTP connHTTP connection to use T The template parameter T specifies the type to return. Possible values are char and ubyte to return char[] or ubyte[]. If asking for char, content will be converted from the connection character set (specified in HTTP response headers or FTP connection properties, both ISO-8859-1 by default) to UTF-8. Examples:import std.net.curl; auto content1 = post("https://httpbin.org/post", ["name1" : "value1", "name2" : "value2"]); auto content2 = post("https://httpbin.org/post", [1,2,3,4]); Returns:A T[] range containing the content of the resource pointed to by the URL.See Also:
- T[]put(Conn = AutoProtocol, T = char, PutUnit)(const(char)[]url, const(PutUnit)[]putData, Connconn= Conn())
 if (isCurlConn!Conn && (is(T == char) || is(T == ubyte)));
- HTTP/FTP put content.Parameters:const(char)[] urlresource to put const(PutUnit)[] putDatadata to send as the body of the request. An array of an arbitrary type is accepted and will be cast to ubyte[] before sending it. Conn connconnection to use e.g. FTP or HTTP. The default AutoProtocol will guess connection type and create a new instance for this call only. The template parameter T specifies the type to return. Possible values are char and ubyte to return char[] or ubyte[]. If asking for char, content will be converted from the connection character set (specified in HTTP response headers or FTP connection properties, both ISO-8859-1 by default) to UTF-8. Example import std.net.curl; auto content = put("https://httpbin.org/put", "Putting this data"); Returns:A T[] range containing the content of the resource pointed to by the URL.See Also:
- voiddel(Conn = AutoProtocol)(const(char)[]url, Connconn= Conn())
 if (isCurlConn!Conn);
- HTTP/FTP delete content.Parameters:const(char)[] urlresource to delete Conn connconnection to use e.g. FTP or HTTP. The default AutoProtocol will guess connection type and create a new instance for this call only. Example import std.net.curl; del("https://httpbin.org/delete"); See Also:
- T[]options(T = char)(const(char)[]url, HTTPconn= HTTP())
 if (is(T == char) || is(T == ubyte));
- HTTP options request.Parameters:const(char)[] urlresource make a option call to HTTP connconnection to use e.g. FTP or HTTP. The default AutoProtocol will guess connection type and create a new instance for this call only. The template parameter T specifies the type to return. Possible values are char and ubyte to return char[] or ubyte[]. Example import std.net.curl; auto http = HTTP(); options("https://httpbin.org/headers", http); writeln("Allow set to " ~ http.responseHeaders["Allow"]); Returns:A T[] range containing the options of the resource pointed to by the URL.See Also:
- T[]trace(T = char)(const(char)[]url, HTTPconn= HTTP())
 if (is(T == char) || is(T == ubyte));
- HTTP trace request.Parameters:const(char)[] urlresource make a trace call to HTTP connconnection to use e.g. FTP or HTTP. The default AutoProtocol will guess connection type and create a new instance for this call only. The template parameter T specifies the type to return. Possible values are char and ubyte to return char[] or ubyte[]. Example import std.net.curl; trace("https://httpbin.org/headers"); Returns:A T[] range containing the trace info of the resource pointed to by the URL.See Also:
- T[]connect(T = char)(const(char)[]url, HTTPconn= HTTP())
 if (is(T == char) || is(T == ubyte));
- HTTP connect request.Parameters:const(char)[] urlresource make a connect to HTTP connHTTP connection to use The template parameter T specifies the type to return. Possible values are char and ubyte to return char[] or ubyte[]. Example import std.net.curl; connect("https://httpbin.org/headers"); Returns:A T[] range containing the connect info of the resource pointed to by the URL.See Also:
- T[]patch(T = char, PatchUnit)(const(char)[]url, const(PatchUnit)[]patchData, HTTPconn= HTTP())
 if (is(T == char) || is(T == ubyte));
- HTTP patch content.Parameters:const(char)[] urlresource to patch const(PatchUnit)[] patchDatadata to send as the body of the request. An array of an arbitrary type is accepted and will be cast to ubyte[] before sending it. HTTP connHTTP connection to use The template parameter T specifies the type to return. Possible values are char and ubyte to return char[] or ubyte[]. Example auto http = HTTP(); http.addRequestHeader("Content-Type", "application/json"); auto content = patch("https://httpbin.org/patch", `{"title": "Patched Title"}`, http); Returns:A T[] range containing the content of the resource pointed to by the URL.See Also:
- autobyLine(Conn = AutoProtocol, Terminator = char, Char = char)(const(char)[]url, KeepTerminatorkeepTerminator= No.keepTerminator, Terminatorterminator= '\x0a', Connconn= Conn())
 if (isCurlConn!Conn && isSomeChar!Char && isSomeChar!Terminator);
- HTTP/FTP fetch content as a range of lines.A range of lines is returned when the request is complete. If the method or other request properties is to be customized then set theconnparameter with a HTTP/FTP instance that has these properties set.Example import std.net.curl, std.stdio; foreach (line; byLine("dlang.org")) writeln(line); Parameters:const(char)[] urlThe url to receive content from KeepTerminator keepTerminatorYes. keepTerminatorsignals that the line terminator should be returned as part of the lines in the range.Terminator terminatorThe character that terminates a line Conn connThe connection to use e.g. HTTP or FTP. Returns:A range of Char[] with the content of the resource pointer to by the URL
- autobyChunk(Conn = AutoProtocol)(const(char)[]url, size_tchunkSize= 1024, Connconn= Conn())
 if (isCurlConn!Conn);
- HTTP/FTP fetch content as a range of chunks.A range of chunks is returned when the request is complete. If the method or other request properties is to be customized then set theconnparameter with a HTTP/FTP instance that has these properties set.Example import std.net.curl, std.stdio; foreach (chunk; byChunk("dlang.org", 100)) writeln(chunk); // chunk is ubyte[100] Parameters:const(char)[] urlThe url to receive content from size_t chunkSizeThe size of each chunk Conn connThe connection to use e.g. HTTP or FTP. Returns:A range of ubyte[chunkSize] with the content of the resource pointer to by the URL
- autobyLineAsync(Conn = AutoProtocol, Terminator = char, Char = char, PostUnit)(const(char)[]url, const(PostUnit)[]postData, KeepTerminatorkeepTerminator= No.keepTerminator, Terminatorterminator= '\x0a', size_ttransmitBuffers= 10, Connconn= Conn())
 if (isCurlConn!Conn && isSomeChar!Char && isSomeChar!Terminator);
 autobyLineAsync(Conn = AutoProtocol, Terminator = char, Char = char)(const(char)[]url, KeepTerminatorkeepTerminator= No.keepTerminator, Terminatorterminator= '\x0a', size_ttransmitBuffers= 10, Connconn= Conn());
- HTTP/FTP fetch content as a range of lines asynchronously.A range of lines is returned immediately and the request that fetches the lines is performed in another thread. If the method or other request properties is to be customized then set theconnparameter with a HTTP/FTP instance that has these properties set. IfpostDatais non-null the method will be set to post for HTTP requests. The background thread will buffer up to transmitBuffers number of lines before it stops receiving data from network. When the main thread reads the lines from the range it frees up buffers and allows for the background thread to receive more data from the network. If no data is available and the main thread accesses the range it will block until data becomes available. An exception to this is the wait(Duration) method on the LineInputRange. This method will wait at maximum for the specified duration and return true if data is available.Example import std.net.curl, std.stdio; // Get some pages in the background auto range1 = byLineAsync("www.google.com"); auto range2 = byLineAsync("www.wikipedia.org"); foreach (line; byLineAsync("dlang.org")) writeln(line); // Lines already fetched in the background and ready foreach (line; range1) writeln(line); foreach (line; range2) writeln(line); import std.net.curl, std.stdio; // Get a line in a background thread and wait in // main thread for 2 seconds for it to arrive. auto range3 = byLineAsync("dlang.com"); if (range3.wait(dur!"seconds"(2))) writeln(range3.front); else writeln("No line received after 2 seconds!"); Parameters:const(char)[] urlThe url to receive content from const(PostUnit)[] postDataData to HTTP Post KeepTerminator keepTerminatorYes. keepTerminatorsignals that the line terminator should be returned as part of the lines in the range.Terminator terminatorThe character that terminates a line size_t transmitBuffersThe number of lines buffered asynchronously Conn connThe connection to use e.g. HTTP or FTP. Returns:A range of Char[] with the content of the resource pointer to by the URL.
- autobyChunkAsync(Conn = AutoProtocol, PostUnit)(const(char)[]url, const(PostUnit)[]postData, size_tchunkSize= 1024, size_ttransmitBuffers= 10, Connconn= Conn())
 if (isCurlConn!Conn);
 autobyChunkAsync(Conn = AutoProtocol)(const(char)[]url, size_tchunkSize= 1024, size_ttransmitBuffers= 10, Connconn= Conn())
 if (isCurlConn!Conn);
- HTTP/FTP fetch content as a range of chunks asynchronously.A range of chunks is returned immediately and the request that fetches the chunks is performed in another thread. If the method or other request properties is to be customized then set theconnparameter with a HTTP/FTP instance that has these properties set. IfpostDatais non-null the method will be set to post for HTTP requests. The background thread will buffer up to transmitBuffers number of chunks before is stops receiving data from network. When the main thread reads the chunks from the range it frees up buffers and allows for the background thread to receive more data from the network. If no data is available and the main thread access the range it will block until data becomes available. An exception to this is the wait(Duration) method on the ChunkInputRange. This method will wait at maximum for the specified duration and return true if data is available.Example import std.net.curl, std.stdio; // Get some pages in the background auto range1 = byChunkAsync("www.google.com", 100); auto range2 = byChunkAsync("www.wikipedia.org"); foreach (chunk; byChunkAsync("dlang.org")) writeln(chunk); // chunk is ubyte[100] // Chunks already fetched in the background and ready foreach (chunk; range1) writeln(chunk); foreach (chunk; range2) writeln(chunk); import std.net.curl, std.stdio; // Get a line in a background thread and wait in // main thread for 2 seconds for it to arrive. auto range3 = byChunkAsync("dlang.com", 10); if (range3.wait(dur!"seconds"(2))) writeln(range3.front); else writeln("No chunk received after 2 seconds!"); Parameters:const(char)[] urlThe url to receive content from const(PostUnit)[] postDataData to HTTP Post size_t chunkSizeThe size of the chunks size_t transmitBuffersThe number of chunks buffered asynchronously Conn connThe connection to use e.g. HTTP or FTP. Returns:A range of ubyte[chunkSize] with the content of the resource pointer to by the URL.
- structHTTP;
- HTTP client functionality.Example import std.net.curl, std.stdio; // Get with custom data receivers auto http = HTTP("dlang.org"); http.onReceiveHeader = (in char[] key, in char[] value) { writeln(key ~ ": " ~ value); }; http.onReceive = (ubyte[] data) { /+ drop +/ return data.length; }; http.perform(); // Put with data senders auto msg = "Hello world"; http.contentLength = msg.length; http.onSend = (void[] data) { auto m = cast(void[]) msg; size_t len = m.length > data.length ? data.length : m.length; if (len == 0) return len; data[0 .. len] = m[0 .. len]; msg = msg[len..$]; return len; }; http.perform(); // Track progress http.method = HTTP.Method.get; http.url = "http://upload.wikimedia.org/wikipedia/commons/" "5/53/Wikipedia-logo-en-big.png"; http.onReceive = (ubyte[] data) { return data.length; }; http.onProgress = (size_t dltotal, size_t dlnow, size_t ultotal, size_t ulnow) { writeln("Progress ", dltotal, ", ", dlnow, ", ", ultotal, ", ", ulnow); return 0; }; http.perform(); See Also:- aliasAuthMethod= etc.c.curl.CurlAuth;
- Authentication method equal to etc.c.curl.CurlAuth
- aliasTimeCond= etc.c.curl.CurlTimeCond;
- Time condition enumeration as an alias of etc.c.curl.CurlTimeCond
- static HTTPopCall(const(char)[]url);
- Constructor taking the url as parameter.
- static HTTPopCall();
- HTTPdup();
- CurlCodeperform(ThrowOnErrorthrowOnError= Yes.throwOnError);
- Perform a http request.After the HTTP client has been setup and possibly assigned callbacks theperform() method will start performing the request towards the specified server.Parameters:ThrowOnError throwOnErrorwhether to throw an exception or return a CurlCode on error 
- @property voidurl(const(char)[]url);
- The URL to specify the location of the resource.
- @property voidcaInfo(const(char)[]caFile);
- Set the CA certificate bundle file to use for SSL peer verification
- aliasrequestPause= etc.c.curl.CurlReadFunc.pause;
- Value to return from onSend/onReceive delegates in order to pause a request
- aliasrequestAbort= etc.c.curl.CurlReadFunc.abort;
- Value to return from onSend delegate in order to abort a request
- @property boolisStopped();
- True if the instance is stopped. A stopped instance is not usable.
- voidshutdown();
- Stop and invalidate this instance.
- @property voidverbose(boolon);
- Set verbose. This will print request information to stderr.
- @property voiddataTimeout(Durationd);
- Set timeout for activity on connection.
- @property voidoperationTimeout(Durationd);
- Set maximum time an operation is allowed to take. This includes dns resolution, connecting, data transfer, etc.
- @property voidconnectTimeout(Durationd);
- Set timeout for connecting.
- @property voidproxy(const(char)[]host);
- ProxySee proxy 
- @property voidproxyPort(ushortport);
- Proxy portSee proxy_port 
- aliasCurlProxy= etc.c.curl.CurlProxy;
- Type of proxy
- @property voidproxyType(CurlProxytype);
- Proxy typeSee proxy_type 
- @property voiddnsTimeout(Durationd);
- DNS lookup timeout.
- @property voidnetInterface(const(char)[]i);
 @property voidnetInterface(const(ubyte)[4]i);
 @property voidnetInterface(InternetAddressi);
- The network interface to use in form of the the IP of the interface.Example theprotocol.netInterface = "192.168.1.32"; theprotocol.netInterface = [ 192, 168, 1, 32 ]; 
- @property voidlocalPort(ushortport);
- Set the local outgoing port to use.Parameters:ushort portthe first outgoing port number to try and use 
- @property voidlocalPortRange(ushortrange);
- Set the local outgoing port range to use. This can be used together with the localPort property.Parameters:ushort rangeif the first port is occupied then try this many port number forwards 
- @property voidtcpNoDelay(boolon);
- Set the tcp no-delay socket option on or off.See nodelay 
- voidsetAuthentication(const(char)[]username, const(char)[]password, const(char)[]domain= "");
- Set the user name, password and optionally domain for authentication purposes.Some protocols may need authentication in some cases. Use this function to provide credentials.Parameters:const(char)[] usernamethe username const(char)[] passwordthe password const(char)[] domainused for NTLM authentication only and is set to the NTLM domain name 
- voidsetProxyAuthentication(const(char)[]username, const(char)[]password);
- Set the user name and password for proxy authentication.Parameters:const(char)[] usernamethe username const(char)[] passwordthe password 
- @property voidonSend(size_t delegate(void[])callback);
- The event handler that gets called when data is needed for sending. The length of the void[] specifies the maximum number of bytes that can be sent.Returns:The callback returns the number of elements in the buffer that have been filled and are ready to send. The special value .abortRequest can be returned in order to abort the current request. The special value .pauseRequest can be returned in order to pause the current request.Example import std.net.curl; string msg = "Hello world"; auto client = HTTP("dlang.org"); client.onSend = delegate size_t(void[] data) { auto m = cast(void[]) msg; size_t length = m.length > data.length ? data.length : m.length; if (length == 0) return 0; data[0 .. length] = m[0 .. length]; msg = msg[length..$]; return length; }; client.perform(); 
- @property voidonReceive(size_t delegate(ubyte[])callback);
- The event handler that receives incoming data. Be sure to copy the incoming ubyte[] since it is not guaranteed to be valid after the callback returns.Returns:The callback returns the incoming bytes read. If not the entire array is the request will abort. The special value .pauseRequest can be returned in order to pause the current request.Example import std.net.curl, std.stdio; auto client = HTTP("dlang.org"); client.onReceive = (ubyte[] data) { writeln("Got data", to!(const(char)[])(data)); return data.length; }; client.perform(); 
- @property voidonProgress(int delegate(size_t dlTotal, size_t dlNow, size_t ulTotal, size_t ulNow)callback);
- Register an event handler that gets called to inform of upload/download progress.Callback parameters 
 Connection type used when the URL should be used to auto detect the protocol. This struct is used as placeholder for the connection parameter when calling the high level API and the connection type (HTTP/FTP) should be guessed by inspecting the URL parameter. The rules for guessing the protocol are: 1, if URL starts with ftp://, ftps:// or ftp. then FTP connection is assumed. 2, HTTP connection otherwise.dlTotaltotal bytes to download dlNowcurrently downloaded bytes ulTotaltotal bytes to upload ulNowcurrently uploaded bytes Callback returns Return 0 to signal success, return non-zero to abort transfer. Example import std.net.curl, std.stdio; auto client = HTTP("dlang.org"); client.onProgress = delegate int(size_t dl, size_t dln, size_t ul, size_t ult) { writeln("Progress: downloaded ", dln, " of ", dl); writeln("Progress: uploaded ", uln, " of ", ul); }; client.perform(); 
- voidclearRequestHeaders();
- Clear all outgoing headers.
- voidaddRequestHeader(const(char)[]name, const(char)[]value);
- Add a header e.g. "X-CustomField: Something is fishy".There is no remove header functionality. Do a clearRequestHeaders and set the needed headers instead.Example import std.net.curl; auto client = HTTP(); client.addRequestHeader("X-Custom-ABC", "This is the custom value"); auto content = get("dlang.org", client); 
- static @property stringdefaultUserAgent();
- The default "User-Agent" value send with a request. It has the form "Phobos-std.net.curl/PHOBOS_VERSION (libcurl/CURL_VERSION)"
- voidsetUserAgent(const(char)[]userAgent);
- Set the value of the user agent request header field.By default a request has it's "User-Agent" field set to defaultUserAgent even ifsetUserAgentwas never called. Pass an empty string to suppress the "User-Agent" field altogether.
- CurlCodegetTiming(CurlInfotiming, ref doubleval);
- Get various timings defined in etc.c.curl.CurlInfo. The value is usable only if the return value is equal to etc.c.curl.CurlError.ok.Parameters:CurlInfo timingone of the timings defined in etc.c.curl.CurlInfo. The values are: etc.c.curl.CurlInfo.namelookup_time, etc.c.curl.CurlInfo.connect_time, etc.c.curl.CurlInfo.pretransfer_time, etc.c.curl.CurlInfo.starttransfer_time, etc.c.curl.CurlInfo.redirect_time, etc.c.curl.CurlInfo.appconnect_time, etc.c.curl.CurlInfo.total_time. double valthe actual value of the inquired timing. Returns:The return code of the operation. The value stored in val should be used only if the return value is etc.c.curl.CurlInfo.ok.Example import std.net.curl; import etc.c.curl : CurlError, CurlInfo; auto client = HTTP("dlang.org"); client.perform(); double val; CurlCode code; code = client.getTiming(CurlInfo.namelookup_time, val); assert(code == CurlError.ok); 
- @property string[string]responseHeaders();
- The headers read from a successful response.
- @property voidmethod(Methodm);
 @property Methodmethod();
- HTTP method used.
- @property StatusLinestatusLine();
- HTTP status line of last response. One call to perform may result in several requests because of redirection.
- voidsetCookie(const(char)[]cookie);
- Set the active cookie string e.g. "name1=value1;name2=value2"
- voidsetCookieJar(const(char)[]path);
- Set a file path to where a cookie jar should be read/stored.
- voidflushCookieJar();
- Flush cookie jar to disk.
- voidclearSessionCookies();
- Clear session cookies.
- voidclearAllCookies();
- Clear all cookies.
- voidsetTimeCondition(HTTP.TimeCondcond, SysTimetimestamp);
- Set time condition on the request.Parameters:HTTP.TimeCond condCurlTimeCond.{none,ifmodsince,ifunmodsince,lastmod} SysTime timestampTimestamp for the condition RFC2616 Section 14.25 
- @property voidpostData(const(void)[]data);
- Specifying data to post when not using the onSend callback.The data is NOT copied by the library. Content-Type will default to application/octet-stream. Data is not converted or encoded by this method.Example import std.net.curl, std.stdio; auto http = HTTP("http://www.mydomain.com"); http.onReceive = (ubyte[] data) { writeln(to!(const(char)[])(data)); return data.length; }; http.postData = [1,2,3,4,5]; http.perform(); 
- @property voidpostData(const(char)[]data);
- Specifying data to post when not using the onSend callback.The data is NOT copied by the library. Content-Type will default to text/plain. Data is not converted or encoded by this method.Example import std.net.curl, std.stdio; auto http = HTTP("http://www.mydomain.com"); http.onReceive = (ubyte[] data) { writeln(to!(const(char)[])(data)); return data.length; }; http.postData = "The quick...."; http.perform(); 
- voidsetPostData(const(void)[]data, stringcontentType);
- Specify data to post when not using the onSend callback, with user-specified Content-Type.Parameters:const(void)[] dataData to post. string contentTypeMIME type of the data, for example, "text/plain" or "application/octet-stream". See also: Internet media type on Wikipedia. import std.net.curl; auto http = HTTP("http://onlineform.example.com"); auto data = "app=login&username=bob&password=s00perS3kret"; http.setPostData(data, "application/x-www-form-urlencoded"); http.onReceive = (ubyte[] data) { return data.length; }; http.perform(); 
- @property voidonReceiveHeader(void delegate(in char[] key, in char[] value)callback);
- Set the event handler that receives incoming headers.The callback will receive a header field key, value as parameter. The const(char)[] arrays are not valid after the delegate has returned.Example import std.net.curl, std.stdio; auto http = HTTP("dlang.org"); http.onReceive = (ubyte[] data) { writeln(to!(const(char)[])(data)); return data.length; }; http.onReceiveHeader = (in char[] key, in char[] value) { writeln(key, " = ", value); }; http.perform(); 
- @property voidonReceiveStatusLine(void delegate(StatusLine)callback);
- Callback for each received StatusLine.Notice that several callbacks can be done for each call to perform() due to redirections.See Also:
- @property voidcontentLength(ulonglen);
- The content length in bytes when using request that has content e.g. POST/PUT and not using chunked transfer. Is set as the "Content-Length" header. Set to ulong.max to reset to chunked transfer.
- @property voidauthenticationMethod(AuthMethodauthMethod);
- Authentication method as specified in AuthMethod.
- @property voidmaxRedirects(uintmaxRedirs);
- Set max allowed redirections using the location header. uint.max for infinite.
- enumMethod: int;
- The standard HTTP methods : RFC2616 Section 5.1.1- head
- get
- post
- put
- del
- options
- trace
- connect
- patch
 
- structStatusLine;
- HTTP status line ie. the first line returned in an HTTP response.If authentication or redirections are done then the status will be for the last response received.- ushortmajorVersion;
- Major HTTP version ie. 1 in HTTP/1.0.
- ushortminorVersion;
- Minor HTTP version ie. 0 in HTTP/1.0.
- ushortcode;
- HTTP status line code e.g. 200.
- stringreason;
- HTTP status line reason string.
- @safe voidreset();
- Reset this status line
- const stringtoString();
 
 
- structFTP;
- FTP client functionality.See Also:- static FTPopCall(const(char)[]url);
- FTP access to the specified url.
- static FTPopCall();
- FTPdup();
- CurlCodeperform(ThrowOnErrorthrowOnError= Yes.throwOnError);
- Performs the ftp request as it has been configured.After a FTP client has been setup and possibly assigned callbacks the perform() method will start performing the actual communication with the server.Parameters:ThrowOnError throwOnErrorwhether to throw an exception or return a CurlCode on error 
- @property voidurl(const(char)[]url);
- The URL to specify the location of the resource.
- aliasrequestPause= etc.c.curl.CurlReadFunc.pause;
- Value to return from onSend/onReceive delegates in order to pause a request
- aliasrequestAbort= etc.c.curl.CurlReadFunc.abort;
- Value to return from onSend delegate in order to abort a request
- @property boolisStopped();
- True if the instance is stopped. A stopped instance is not usable.
- voidshutdown();
- Stop and invalidate this instance.
- @property voidverbose(boolon);
- Set verbose. This will print request information to stderr.
- @property voiddataTimeout(Durationd);
- Set timeout for activity on connection.
- @property voidoperationTimeout(Durationd);
- Set maximum time an operation is allowed to take. This includes dns resolution, connecting, data transfer, etc.
- @property voidconnectTimeout(Durationd);
- Set timeout for connecting.
- @property voidproxy(const(char)[]host);
- ProxySee proxy 
- @property voidproxyPort(ushortport);
- Proxy portSee proxy_port 
- aliasCurlProxy= etc.c.curl.CurlProxy;
- Type of proxy
- @property voidproxyType(CurlProxytype);
- Proxy typeSee proxy_type 
- @property voiddnsTimeout(Durationd);
- DNS lookup timeout.
- @property voidnetInterface(const(char)[]i);
 @property voidnetInterface(const(ubyte)[4]i);
 @property voidnetInterface(InternetAddressi);
- The network interface to use in form of the the IP of the interface.Example theprotocol.netInterface = "192.168.1.32"; theprotocol.netInterface = [ 192, 168, 1, 32 ]; 
- @property voidlocalPort(ushortport);
- Set the local outgoing port to use.Parameters:ushort portthe first outgoing port number to try and use 
- @property voidlocalPortRange(ushortrange);
- Set the local outgoing port range to use. This can be used together with the localPort property.Parameters:ushort rangeif the first port is occupied then try this many port number forwards 
- @property voidtcpNoDelay(boolon);
- Set the tcp no-delay socket option on or off.See nodelay 
- voidsetAuthentication(const(char)[]username, const(char)[]password, const(char)[]domain= "");
- Set the user name, password and optionally domain for authentication purposes.Some protocols may need authentication in some cases. Use this function to provide credentials.Parameters:const(char)[] usernamethe username const(char)[] passwordthe password const(char)[] domainused for NTLM authentication only and is set to the NTLM domain name 
- voidsetProxyAuthentication(const(char)[]username, const(char)[]password);
- Set the user name and password for proxy authentication.Parameters:const(char)[] usernamethe username const(char)[] passwordthe password 
- @property voidonSend(size_t delegate(void[])callback);
- The event handler that gets called when data is needed for sending. The length of the void[] specifies the maximum number of bytes that can be sent.Returns:The callback returns the number of elements in the buffer that have been filled and are ready to send. The special value .abortRequest can be returned in order to abort the current request. The special value .pauseRequest can be returned in order to pause the current request.
- @property voidonReceive(size_t delegate(ubyte[])callback);
- The event handler that receives incoming data. Be sure to copy the incoming ubyte[] since it is not guaranteed to be valid after the callback returns.Returns:The callback returns the incoming bytes read. If not the entire array is the request will abort. The special value .pauseRequest can be returned in order to pause the current request.
- @property voidonProgress(int delegate(size_t dlTotal, size_t dlNow, size_t ulTotal, size_t ulNow)callback);
- The event handler that gets called to inform of upload/download progress.Callback parameters 
 Connection type used when the URL should be used to auto detect the protocol. This struct is used as placeholder for the connection parameter when calling the high level API and the connection type (HTTP/FTP) should be guessed by inspecting the URL parameter. The rules for guessing the protocol are: 1, if URL starts with ftp://, ftps:// or ftp. then FTP connection is assumed. 2, HTTP connection otherwise.dlTotaltotal bytes to download dlNowcurrently downloaded bytes ulTotaltotal bytes to upload ulNowcurrently uploaded bytes Callback returns Return 0 from the callback to signal success, return non-zero to abort transfer. 
- voidclearCommands();
- Clear all commands send to ftp server.
- voidaddCommand(const(char)[]command);
- Add a command to send to ftp server.There is no remove command functionality. Do a clearCommands and set the needed commands instead.Example import std.net.curl; auto client = FTP(); client.addCommand("RNFR my_file.txt"); client.addCommand("RNTO my_renamed_file.txt"); upload("my_file.txt", "ftp.digitalmars.com", client); 
- @property voidencoding(stringname);
 @property stringencoding();
- Connection encoding. Defaults to ISO-8859-1.
- @property voidcontentLength(ulonglen);
- The content length in bytes of the ftp data.
- CurlCodegetTiming(CurlInfotiming, ref doubleval);
- Get various timings defined in etc.c.curl.CurlInfo. The value is usable only if the return value is equal to etc.c.curl.CurlError.ok.Parameters:CurlInfo timingone of the timings defined in etc.c.curl.CurlInfo. The values are: etc.c.curl.CurlInfo.namelookup_time, etc.c.curl.CurlInfo.connect_time, etc.c.curl.CurlInfo.pretransfer_time, etc.c.curl.CurlInfo.starttransfer_time, etc.c.curl.CurlInfo.redirect_time, etc.c.curl.CurlInfo.appconnect_time, etc.c.curl.CurlInfo.total_time. double valthe actual value of the inquired timing. Returns:The return code of the operation. The value stored in val should be used only if the return value is etc.c.curl.CurlInfo.ok.Example import std.net.curl; import etc.c.curl : CurlError, CurlInfo; auto client = FTP(); client.addCommand("RNFR my_file.txt"); client.addCommand("RNTO my_renamed_file.txt"); upload("my_file.txt", "ftp.digitalmars.com", client); double val; CurlCode code; code = client.getTiming(CurlInfo.namelookup_time, val); assert(code == CurlError.ok); 
 
- structSMTP;
- Basic SMTP protocol support.Example import std.net.curl; // Send an email with SMTPS auto smtp = SMTP("smtps://smtp.gmail.com"); smtp.setAuthentication("[email protected]", "password"); smtp.mailTo = ["<[email protected]>"]; smtp.mailFrom = "<[email protected]>"; smtp.message = "Example Message"; smtp.perform(); See Also:- static SMTPopCall(const(char)[]url);
- Sets to the URL of the SMTP server.
- static SMTPopCall();
- CurlCodeperform(ThrowOnErrorthrowOnError= Yes.throwOnError);
- Performs the request as configured.Parameters:ThrowOnError throwOnErrorwhether to throw an exception or return a CurlCode on error 
- @property voidurl(const(char)[]url);
- The URL to specify the location of the resource.
- aliasrequestPause= etc.c.curl.CurlReadFunc.pause;
- Value to return from onSend/onReceive delegates in order to pause a request
- aliasrequestAbort= etc.c.curl.CurlReadFunc.abort;
- Value to return from onSend delegate in order to abort a request
- @property boolisStopped();
- True if the instance is stopped. A stopped instance is not usable.
- voidshutdown();
- Stop and invalidate this instance.
- @property voidverbose(boolon);
- Set verbose. This will print request information to stderr.
- @property voiddataTimeout(Durationd);
- Set timeout for activity on connection.
- @property voidoperationTimeout(Durationd);
- Set maximum time an operation is allowed to take. This includes dns resolution, connecting, data transfer, etc.
- @property voidconnectTimeout(Durationd);
- Set timeout for connecting.
- @property voidproxy(const(char)[]host);
- ProxySee proxy 
- @property voidproxyPort(ushortport);
- Proxy portSee proxy_port 
- aliasCurlProxy= etc.c.curl.CurlProxy;
- Type of proxy
- @property voidproxyType(CurlProxytype);
- Proxy typeSee proxy_type 
- @property voiddnsTimeout(Durationd);
- DNS lookup timeout.
- @property voidnetInterface(const(char)[]i);
 @property voidnetInterface(const(ubyte)[4]i);
 @property voidnetInterface(InternetAddressi);
- The network interface to use in form of the the IP of the interface.Example theprotocol.netInterface = "192.168.1.32"; theprotocol.netInterface = [ 192, 168, 1, 32 ]; 
- @property voidlocalPort(ushortport);
- Set the local outgoing port to use.Parameters:ushort portthe first outgoing port number to try and use 
- @property voidlocalPortRange(ushortrange);
- Set the local outgoing port range to use. This can be used together with the localPort property.Parameters:ushort rangeif the first port is occupied then try this many port number forwards 
- @property voidtcpNoDelay(boolon);
- Set the tcp no-delay socket option on or off.See nodelay 
- voidsetAuthentication(const(char)[]username, const(char)[]password, const(char)[]domain= "");
- Set the user name, password and optionally domain for authentication purposes.Some protocols may need authentication in some cases. Use this function to provide credentials.Parameters:const(char)[] usernamethe username const(char)[] passwordthe password const(char)[] domainused for NTLM authentication only and is set to the NTLM domain name 
- voidsetProxyAuthentication(const(char)[]username, const(char)[]password);
- Set the user name and password for proxy authentication.Parameters:const(char)[] usernamethe username const(char)[] passwordthe password 
- @property voidonSend(size_t delegate(void[])callback);
- The event handler that gets called when data is needed for sending. The length of the void[] specifies the maximum number of bytes that can be sent.Returns:The callback returns the number of elements in the buffer that have been filled and are ready to send. The special value .abortRequest can be returned in order to abort the current request. The special value .pauseRequest can be returned in order to pause the current request.
- @property voidonReceive(size_t delegate(ubyte[])callback);
- The event handler that receives incoming data. Be sure to copy the incoming ubyte[] since it is not guaranteed to be valid after the callback returns.Returns:The callback returns the incoming bytes read. If not the entire array is the request will abort. The special value .pauseRequest can be returned in order to pause the current request.
- @property voidonProgress(int delegate(size_t dlTotal, size_t dlNow, size_t ulTotal, size_t ulNow)callback);
- The event handler that gets called to inform of upload/download progress.Callback parameters 
 Connection type used when the URL should be used to auto detect the protocol. This struct is used as placeholder for the connection parameter when calling the high level API and the connection type (HTTP/FTP) should be guessed by inspecting the URL parameter. The rules for guessing the protocol are: 1, if URL starts with ftp://, ftps:// or ftp. then FTP connection is assumed. 2, HTTP connection otherwise.dlTotaltotal bytes to download dlNowcurrently downloaded bytes ulTotaltotal bytes to upload ulNowcurrently uploaded bytes Callback returns Return 0 from the callback to signal success, return non-zero to abort transfer. 
- @property voidmailFrom()(const(char)[]sender);
- Setter for the sender's email address.
- voidmailTo()(const(char)[][]recipients...);
- Setter for the recipient email addresses.
- @property voidmessage(stringmsg);
- Sets the message body text.
 
- classCurlException: object.Exception;
- Exception thrown on errors in std.net.curl functions.- pure nothrow @safe this(stringmsg, stringfile= __FILE__, size_tline= __LINE__, Throwablenext= null);
- Parameters:string msgThe message for the exception. string fileThe file where the exception occurred. size_t lineThe line number where the exception occurred. Throwable nextThe previous exception in the chain of exceptions, if any. 
 
- classCurlTimeoutException: std.net.curl.CurlException;
- Exception thrown on timeout errors in std.net.curl functions.- pure nothrow @safe this(stringmsg, stringfile= __FILE__, size_tline= __LINE__, Throwablenext= null);
- Parameters:string msgThe message for the exception. string fileThe file where the exception occurred. size_t lineThe line number where the exception occurred. Throwable nextThe previous exception in the chain of exceptions, if any. 
 
- classHTTPStatusException: std.net.curl.CurlException;
- Exception thrown on HTTP request failures, e.g. 404 Not Found.- pure nothrow @safe this(intstatus, stringmsg, stringfile= __FILE__, size_tline= __LINE__, Throwablenext= null);
- Parameters:int statusThe HTTP status code. string msgThe message for the exception. string fileThe file where the exception occurred. size_t lineThe line number where the exception occurred. Throwable nextThe previous exception in the chain of exceptions, if any. 
- immutable intstatus;
- The HTTP status code
 
- aliasCurlCode= int;
- Equal to etc.c.curl.CURLcode
- aliasThrowOnError= std.typecons.Flag!"throwOnError".Flag;
- Flag to specify whether or not an exception is thrown on error.
- structCurl;
- Wrapper to provide a better interface to libcurl than using the plain C API. It is recommended to use the HTTP/FTP etc. structs instead unless raw access to libcurl is needed.Warning This struct uses interior pointers for callbacks. Only allocate it on the stack if you never move or copy it. This also means passing by reference when passing Curl to other functions. Otherwise always allocate on the heap. - voidinitialize();
- Initialize the instance by creating a working curl handle.
- const @property boolstopped();
- Curldup();
- Duplicate this handle.The new handle will have all options set as the one it was duplicated from. An exception to this is that all options that cannot be shared across threads are reset thereby making it safe to use the duplicate in a new thread.
- voidshutdown();
- Stop and invalidate this curl instance.Warning Do not call this from inside a callback handler e.g. onReceive. 
- voidpause(boolsendingPaused, boolreceivingPaused);
- Pausing and continuing transfers.
- voidset(CurlOptionoption, const(char)[]value);
- Set a string curl option.Parameters:CurlOption optionA etc.c.curl.CurlOption as found in the curl documentation const(char)[] valueThe string 
- voidset(CurlOptionoption, longvalue);
- Set a long curl option.Parameters:CurlOption optionA etc.c.curl.CurlOption as found in the curl documentation long valueThe long 
- voidset(CurlOptionoption, void*value);
- Set a void* curl option.Parameters:CurlOption optionA etc.c.curl.CurlOption as found in the curl documentation void* valueThe pointer 
- voidclear(CurlOptionoption);
- Clear a pointer option.Parameters:CurlOption optionA etc.c.curl.CurlOption as found in the curl documentation 
- voidclearIfSupported(CurlOptionoption);
- Clear a pointer option. Does not raise an exception if the underlying libcurl does not support the option. Use sparingly.Parameters:CurlOption optionA etc.c.curl.CurlOption as found in the curl documentation 
- CurlCodeperform(ThrowOnErrorthrowOnError= Yes.throwOnError);
- perform the curl request by doing the HTTP,FTP etc. as it has been setup beforehand.Parameters:ThrowOnError throwOnErrorwhether to throw an exception or return a CurlCode on error 
- CurlCodegetTiming(CurlInfotiming, ref doubleval);
- Get the various timings like name lookup time, total time, connect time etc. The timed category is passed through the timing parameter while the timing value is stored at val. The value is usable only if res is equal to etc.c.curl.CurlError.ok.
- @property voidonReceive(size_t delegate(InData)callback);
- The event handler that receives incoming data.Parameters:size_t delegate(InData) callbackthe callback that receives the ubyte[] data. Be sure to copy the incoming data and not store a slice. Returns:The callback returns the incoming bytes read. If not the entire array is the request will abort. The special value HTTP.pauseRequest can be returned in order to pause the current request.Example import std.net.curl, std.stdio; Curl curl; curl.initialize(); curl.set(CurlOption.url, "http://dlang.org"); curl.onReceive = (ubyte[] data) { writeln("Got data", to!(const(char)[])(data)); return data.length;}; curl.perform(); 
- @property voidonReceiveHeader(void delegate(in char[])callback);
- The event handler that receives incoming headers for protocols that uses headers.Parameters:void delegate(in char[]) callbackthe callback that receives the header string. Make sure the callback copies the incoming params if it needs to store it because they are references into the backend and may very likely change. Example import std.net.curl, std.stdio; Curl curl; curl.initialize(); curl.set(CurlOption.url, "http://dlang.org"); curl.onReceiveHeader = (in char[] header) { writeln(header); }; curl.perform(); 
- @property voidonSend(size_t delegate(OutData)callback);
- The event handler that gets called when data is needed for sending.Parameters:size_t delegate(OutData) callbackthe callback that has a void[] buffer to be filled Returns:The callback returns the number of elements in the buffer that have been filled and are ready to send. The special value Curl.abortRequest can be returned in order to abort the current request. The special value Curl.pauseRequest can be returned in order to pause the current request.Example import std.net.curl; Curl curl; curl.initialize(); curl.set(CurlOption.url, "http://dlang.org"); string msg = "Hello world"; curl.onSend = (void[] data) { auto m = cast(void[]) msg; size_t length = m.length > data.length ? data.length : m.length; if (length == 0) return 0; data[0 .. length] = m[0 .. length]; msg = msg[length..$]; return length; }; curl.perform(); 
- @property voidonSeek(CurlSeek delegate(long, CurlSeekPos)callback);
- The event handler that gets called when the curl backend needs to seek the data to be sent.Parameters:CurlSeek delegate(long, CurlSeekPos) callbackthe callback that receives a seek offset and a seek position etc.c.curl.CurlSeekPos Returns:The callback returns the success state of the seeking etc.c.curl.CurlSeekExample import std.net.curl; Curl curl; curl.initialize(); curl.set(CurlOption.url, "http://dlang.org"); curl.onSeek = (long p, CurlSeekPos sp) { return CurlSeek.cantseek; }; curl.perform(); 
- @property voidonSocketOption(int delegate(curl_socket_t, CurlSockType)callback);
- The event handler that gets called when the net socket has been created but a connect() call has not yet been done. This makes it possible to set misc. socket options.Parameters:int delegate(curl_socket_t, CurlSockType) callbackthe callback that receives the socket and socket type etc.c.curl.CurlSockType Returns:Return 0 from the callback to signal success, return 1 to signal error and make curl close the socketExample import std.net.curl; Curl curl; curl.initialize(); curl.set(CurlOption.url, "http://dlang.org"); curl.onSocketOption = delegate int(curl_socket_t s, CurlSockType t) { /+ do stuff +/ }; curl.perform(); 
- @property voidonProgress(int delegate(size_t dlTotal, size_t dlNow, size_t ulTotal, size_t ulNow)callback);
- The event handler that gets called to inform of upload/download progress.Parameters:int delegate(size_t dlTotal, size_t dlNow, size_t ulTotal, size_t ulNow) callbackthe callback that receives the (total bytes to download, currently downloaded bytes, total bytes to upload, currently uploaded bytes). Returns:Return 0 from the callback to signal success, return non-zero to abort transferExample import std.net.curl; Curl curl; curl.initialize(); curl.set(CurlOption.url, "http://dlang.org"); curl.onProgress = delegate int(size_t dltotal, size_t dlnow, size_t ultotal, size_t uln) { writeln("Progress: downloaded bytes ", dlnow, " of ", dltotal); writeln("Progress: uploaded bytes ", ulnow, " of ", ultotal); curl.perform(); };