Image Uploader Scripting API
Public Member Functions | List of all members
NetworkClient Class Reference

HTTP/FTP client (libcurl wrapper). More...

Public Member Functions

 addQueryHeader (string name, string value)
 
 addQueryParam (string name, string value)
 
 addQueryParamFile (string name, string fileName, string displayName, string contentType)
 
bool doGet (string url)
 
bool doPost (string data)
 
bool doUpload (string fileName, string data)
 
bool doUploadMultipartData ()
 
 enableResponseCodeChecking (bool enable)
 
string errorString ()
 
double getCurlInfoDouble (int option)
 
int getCurlInfoInt (int option)
 
string getCurlInfoString (int option)
 
int getCurlResult ()
 
string getCurlResultString ()
 
string responseBody ()
 
int responseCode ()
 
string responseHeaderByIndex (int index, string name)
 
string responseHeaderByName (string name)
 
int responseHeaderCount ()
 
string responseHeaderText ()
 
 setChunkOffset (double offset)
 
 setChunkSize (double size)
 
 setCurlOption (int option, string value)
 
 setCurlOptionInt (int option, long value)
 
 setMethod (string str)
 
 setOutputFile (string str)
 
 setReferer (string str)
 
 setUrl (string url)
 
 setUserAgent (string userAgentStr)
 
string urlEncode (string str)
 

Detailed Description

HTTP/FTP client (libcurl wrapper).

Note: After each completed request, most of the options are set to default values.

Member Function Documentation

addQueryHeader ( string   name,
string   value 
)

Example:

nm.addQueryHeader("User-Agent", "Mozilla/5.0");
bool doGet ( string   url = "")

Example 1

nm.doGet("http://google.com/?q=" + nm.urlEncode("Smelly cat");
print(nc.responseBody());

Example 2

nm.setOutputFile("d:\\image.png"); //only UTF-8 file names are supported on Windows
nm.doGet("http://i.imgur.com/DDf2wbJ.png");
bool doPost ( string   data = "")

Example 1

nm.setUrl("https://www.googleapis.com/oauth2/v3/token");
nm.addQueryParam("refresh_token", refreshToken);
nm.addQueryParam("client_id", clientId);
nm.addQueryParam("client_secret", clientSecret);
nm.addQueryParam("grant_type", "refresh_token");
nm.doPost("");
print(nm.responseBody());

Example 2

//POST request from raw data
nm.setUrl("https://www.googleapis.com/oauth2/v3/token");
nm.doPost("param1=value&param=value");
bool doUpload ( string   fileName,
string   data 
)

Example 1

nm.setMethod("PUT");
nm.setUrl("https://www.googleapis.com/drive/v2/files/" + id);
nm.addQueryHeader("Authorization", "Basic ");
nm.addQueryHeader("Content-Type", "application/json");
local postData = {title= "SmellyCat.jpg"};
nm.doUpload("", ToJSON(postData));

Example 2

local fileName = "c:\\test\\file.txt";
nc.setUrl("ftp://example.com");
nc.setMethod("PUT");
nc.doUpload(fileName, "");
bool doUploadMultipartData ( )

Example

local fileName = "c:\\test\\file.txt"; //only UTF-8 file names are supported on Windows
nm.setUrl("http://takebin.com/action");
nm.addQueryParamFile("file", fileName, ExtractFileName(FileName),"");
nm.addQueryParam("fileDesc", "cool file");
nm.doUploadMultipartData();
if ( nm.responseCode() == 200 ) {
print(nm.responseBody());
}
setChunkOffset ( double  offset)

Set the byte offset of current chunk, relative to the beginning of the full file.

Since
1.3.0
setChunkSize ( double  size)

Sets size of current chunk.

Since
1.3.0