NetworkRequest
Package: Libraries.Network · Inherits from: Libraries.Language.Object
This class is used by the NetworkConnection class to create a request to be made over the internet protocol. More information on the internet protocol, called Hyper Text Transfer Protocol (HTTP) can be found at: https://www.w3.org/Protocols/,
Example Code
use Libraries.Network.NetworkConnection
use Libraries.Network.NetworkRequest
use Libraries.Network.NetworkResponseEvent
use Libraries.Network.NetworkRequestListener
class Main is NetworkRequestListener
action Main
NetworkRequest request
request:SetRequestTypeToGet()
request:SetWebAddress("https://quorumlanguage.com/GETtest.php")
NetworkConnection http
http:AddListener(me)
http:SendRequest(request)
end
action ResponseReceived(NetworkResponseEvent response)
output response:GetResponseText()
end
end
Actions
AddHeader(text key, text value)
This method adds a header to a NetworkRequest object.
Parameters
keytext: The name of the headervaluetext: The value of the header
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:AddHeader("Accept-Encoding", "gzip, deflate")
end
end
ApplyCharacterFormatting(text value)
This method is used to format a text value in "url encode" format.
Parameters
valuetext: The unformatted string.
Returns
text: The formatted string.
Example
use Libraries.Data.Formats.JavaScriptObjectNotation
use Libraries.Containers.Iterator
action FormEncodeData(JavaScriptObjectNotation data) returns text
text result = ""
Iterator<JavaScriptObjectNotation> it = data:GetIterator()
repeat while it:HasNext()
JavaScriptObjectNotation obj
obj = it:Next()
text key = obj:GetKey()
result = result + key + "=" + obj:GetValue() + "&"
end
result = result:GetSubtext(0, result:GetSize() - 1)
return ApplyCharacterFormatting(result)
end
FormEncodeData(Libraries.Data.Formats.JavaScriptObjectNotation data)
This method is used to url encode a text value from a JavaScriptObjectNotation.
Parameters
dataLibraries.Data.Formats.JavaScriptObjectNotation: A JavaScriptObjectNotation object to encode.
Returns
text: The formatted string.
Example
use Libraries.Data.Formats.JavaScriptObjectNotation
use Libraries.Containers.Iterator
action SetBodyAsFormEncodedData(JavaScriptObjectNotation data)
text body = FormEncodeData(data)
end
FormEncodeData(Libraries.Containers.HashTable<text:text> data)
This method is used to url encode a text value from a HashTable.
Parameters
dataLibraries.Containers.HashTable<text:text>: A HashTable containing key value pairs to encode.
Returns
text: The formatted string.
Example
use Libraries.Containers.HashTable
use Libraries.Containers.Iterator
action SetBodyAsFormEncodedData(JavaScriptObjectNotation data)
text body = FormEncodeData(data)
end
GetBody()
This method gets the body of the NetworkRequest object.
Returns
text: The body of the request object.
Example
use Libraries.Network.NetworkRequest
class Main
action Main
text key = "name"
text value = "John"
NetworkRequest request
request:SetBody(key + ":" + value)
output request:GetBody()
end
end
GetChunkLength()
This method gets the size of the chunks if chunked length streaming mode is on in the NetworkRequest object.
Returns
integer: The chunk size in bytes.
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetChunkedStreamingMode(true)
request:SetChunkLength(1000)
output request:GetChunkLength()
end
end
GetConnectTimeout()
This method gets the connection timeout value for the NetworkRequest object.
Returns
integer: The timeeout value in milliseconds.
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetConnectTimeout(1000)
output request:GetConnectTimeout()
end
end
GetDoInput()
This method returns a boolean value based on whether or not the NetworkRequest object will provide input to the server.
Returns
boolean: A boolean value to indicate if the object will send input.
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetDoInput(true)
output request:GetDoInput()
end
end
GetDoOutput()
This method returns a boolean value based on whether or not the NetworkRequest object will get output from the server.
Returns
boolean: A boolean value to indicate if the object will receive output.
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetDoOutput(true)
output request:GetDoOutput()
end
end
GetDownloadFile()
Use this method to retrieve the file name from a NetworkRequest object for a file to be downloaded.
Returns
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetDownloadFile("logo.png")
output request:GetDownloadFile():GetAbsolutePath()
end
end
GetHeaders()
This method gets a HashTable of the headers of a NetworkRequest object.
Returns
Libraries.Containers.HashTable<text:text>: A HashTable of headers.
Example
use Libraries.Network.NetworkRequest
use Libraries.Containers.HashTable
class Main
action Main
NetworkRequest request
request:AddHeader("Accept-Encoding", "gzip, deflate")
HashTable<text, text> headers = request:GetHeaders()
output headers:GetValue("Accept-Encoding")
end
end
GetParameters()
This method gets the parameters of the NetworkRequest object.
Returns
text: The parameters of the request object.
Example
use Libraries.Network.NetworkRequest
use Libraries.Data.Formats.JavaScriptObjectNotation
class Main
action Main
JavaScriptObjectNotation data
data:Add("first", "John")
data:Add("last", "Doe")
NetworkRequest request
request:SetParameters(data)
output request:GetParameters()
end
end
GetReadTimeout()
This method returns the read timeout value of a NetworkRequest.
Returns
integer: The read timeout value in milliseconds.
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
output request:GetReadTimeout()
end
end
GetRequestType()
This method gets the request type of a NetworkRequest object.
Returns
text: The type of request as text.
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetRequestTypeToPost()
output request:GetRequestType()
end
end
GetWebAddress()
This method gets the web address for the NetworkRequest object.
Returns
text: The web address of the object.
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetWebAddress("https://quorumlanguage.com/GETtest.php")
output request:GetWebAddress()
end
end
IsChunkedStreamingMode()
This method returns a boolean value to determine if chunked length streaming mode is on in the NetworkRequest object.
Returns
boolean: A boolean value indicating the setting of the mode.
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetChunkedStreamingMode(true)
output request:IsChunkedStreamingMode()
end
end
IsFixedLengthStreamingMode()
This method returns a boolean value to determine if fixed length streaming mode is on in the NetworkRequest object.
Returns
boolean: A boolean value indicating the setting of the mode.
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetFixedLengthStreamingMode(false)
output request:IsFixedLengthStreamingMode()
end
end
SetBody(text data)
This method sets the body of the NetworkRequest object.
Parameters
datatext: The body of the request object.
Example
use Libraries.Network.NetworkRequest
class Main
action Main
text key = "name"
text value = "John"
NetworkRequest request
request:SetBody(key + ":" + value)
output request:GetBody()
end
end
SetBodyAsJavaScriptObjectNotation(Libraries.Containers.HashTable<text:text> data)
This method sets the body of the NetworkRequest object as JavaScriptObjectNotation data from a JavaScriptObjectNotation object.
Parameters
Example
use Libraries.Network.NetworkRequest
use Libraries.Containers.HashTable
class Main
action Main
text key1 = "name"
text value1 = "John"
text key2 = "age"
text value2 = "21"
HashTable<text, text> data
data:Add(key1, value1)
data:Add(key2, value2)
NetworkRequest request
request:SetBodyAsJavaScriptObjectNotation(data)
output request:GetBody()
end
end
SetBodyAsJavaScriptObjectNotation(Libraries.Data.Formats.JavaScriptObjectNotation data)
This method sets the body of the NetworkRequest object as JavaScriptObjectNotation data from a JavaScriptObjectNotation object.
Parameters
Example
use Libraries.Network.NetworkRequest
use Libraries.Data.Formats.JavaScriptObjectNotation
class Main
action Main
text key1 = "name"
text value1 = "John"
text key2 = "age"
text value2 = "21"
JavaScriptObjectNotation data
data:Add(key1, value1)
data:Add(key2, value2)
NetworkRequest request
request:SetBodyAsJavaScriptObjectNotation(data)
output request:GetBody()
end
end
SetChunkLength(integer chunkLength)
This method sets the size of the chunks if chunked length streaming mode is on in the NetworkRequest object.
Parameters
chunkLengthinteger: The chunk size in bytes.
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetChunkedStreamingMode(true)
request:SetChunkLength(1000)
output request:GetChunkLength()
end
end
SetChunkedStreamingMode(boolean value)
This method is sets the NetworkRequest to chunked streaming mode.
Parameters
valueboolean: A boolean value to set the mode on or off.
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetChunkedStreamingMode(true)
output request:IsChunkedStreamingMode()
end
end
SetConnectTimeout(integer milliseconds)
This method sets the connection timeout value for the NetworkRequest object.
Parameters
millisecondsinteger: The timeeout value in milliseconds.
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetConnectTimeout(1000)
output request:GetConnectTimeout()
end
end
SetDoInput(boolean value)
This method sets NetworkRequest object to provide input to the server.
Parameters
valueboolean: The boolean value for the setting.
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetDoInput(false)
output request:GetDoInput()
end
end
SetDoOutput(boolean value)
This method sets NetworkRequest object to receive output from the server.
Parameters
valueboolean: The boolean value for the setting.
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetDoOutput(false)
output request:GetDoOutput()
end
end
SetDownloadFile(Libraries.System.File downloadFile)
Use this method to download a file from the internet. Set the filename and path where you'd like the downloaded file to save on your local computer.
Parameters
downloadFileLibraries.System.File: The file object target for the download
Example
use Libraries.Network.NetworkConnection
use Libraries.Network.NetworkRequest
use Libraries.Network.NetworkRequestListener
use Libraries.Network.NetworkResponseEvent
use Libraries.System.File
class Main is NetworkRequestListener
action Main
NetworkConnection conn
conn:AddListener(me)
File myFile
myFile:SetPath("logo.png")
NetworkRequest request
request:SetRequestTypeToGet()
request:SetWebAddress("https://quorumlanguage.com/media/QuorumLogo.png")
request:SetDownloadFile(myFile)
conn:SendRequest(request)
end
action ResponseReceived(NetworkResponseEvent response)
output response:GetResponseText()
end
end
SetDownloadFile(text downloadFile)
Use this method to download a file from the internet. Set the filename and path where you'd like the downloaded file to save on your local computer.
Parameters
downloadFiletext: The relative path to the working directory.
Example
use Libraries.Network.NetworkConnection
use Libraries.Network.NetworkRequest
use Libraries.Network.NetworkRequestListener
use Libraries.Network.NetworkResponseEvent
class Main is NetworkRequestListener
action Main
NetworkConnection conn
conn:AddListener(me)
NetworkRequest request
request:SetRequestTypeToGet()
request:SetWebAddress("https://quorumlanguage.com/media/QuorumLogo.png")
request:SetDownloadFile("logo.png")
conn:SendRequest(request)
end
action ResponseReceived(NetworkResponseEvent response)
output response:GetResponseText()
end
end
SetFixedLengthStreamingMode(boolean value)
This method is sets the NetworkRequest to fixed length streaming mode.
Parameters
valueboolean: A boolean value to set the mode on or off.
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetFixedLengthStreamingMode(true)
output request:IsFixedLengthStreamingMode()
end
end
SetHeaders(Libraries.Containers.HashTable<text:text> headers)
This method sets the headers of a NetworkRequest object from a HashTable.
Parameters
Example
use Libraries.Network.NetworkRequest
use Libraries.Containers.HashTable
class Main
action Main
HashTable<text, text> headers
headers:Add("Connection", "keep-alive")
headers:Add("Accept-Encoding", "gzip, deflate")
NetworkRequest request
request:SetHeaders(headers)
output headers:GetValue("Connection")
end
end
SetParameters(Libraries.Data.Formats.JavaScriptObjectNotation data)
This method sets the body of the NetworkRequest object as form encoded data from a JavaScriptObjectNotation object.
Parameters
Example
use Libraries.Network.NetworkRequest
use Libraries.Data.Formats.JavaScriptObjectNotation
class Main
action Main
text key1 = "name"
text value1 = "John"
text key2 = "age"
text value2 = "21"
JavaScriptObjectNotation data
data:Add(key1, value1)
data:Add(key2, value2)
NetworkRequest request
request:SetRequestTypeToGet()
request:SetParameters(data)
output request:GetBody()
end
end
SetParameters(Libraries.Containers.HashTable<text:text> data)
This method sets the parameters of the NetworkRequest object as form encoded data from a HashTable.
Parameters
Example
use Libraries.Network.NetworkRequest
use Libraries.Containers.HashTable
class Main
action Main
text key1 = "name"
text value1 = "John"
text key2 = "age"
text value2 = "21"
HashTable<text, text> data
data:Add(key1, value1)
data:Add(key2, value2)
NetworkRequest request
request:SetRequestTypeToPost()
request:SetParameters(data)
output request:GetParameters()
end
end
SetReadTimeout(integer milliseconds)
This method sets the read timeout value of a NetworkRequest.
Parameters
millisecondsinteger: The read timeout value in milliseconds.
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetReadTimeout(1000)
output request:GetReadTimeout()
end
end
SetRequestType(Libraries.Network.NetworkRequestType type)
This method is used to set the request type of a NetworkRequest
Parameters
typeLibraries.Network.NetworkRequestType: The NetworkRequestType object
Example
use Libraries.Network.NetworkRequest
use Libraries.Network.NetworkRequestType
class Main
action Main
NetworkRequestType type
type:SetToGet()
NetworkRequest request
request:SetRequestType(type)
end
end
SetRequestTypeToDelete()
This method is used to set the request type of a NetworkRequest to DELETE
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetRequestTypeToDelete()
end
end
SetRequestTypeToGet()
This method is used to set the request type of a NetworkRequest to GET
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetRequestTypeToGet()
end
end
SetRequestTypeToHead()
This method is used to set the request type of a NetworkRequest to HEAD
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetRequestTypeToHead()
end
end
SetRequestTypeToPatch()
This method is used to set the request type of a NetworkRequest to PATCH
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetRequestTypeToPatch()
end
end
SetRequestTypeToPost()
This method is used to set the request type of a NetworkRequest to POST
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetRequestTypeToPost()
end
end
SetRequestTypeToPut()
This method is used to set the request type of a NetworkRequest to PUT
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetRequestTypeToPut()
end
end
SetWebAddress(text webAddress)
This method sets the web address for the NetworkRequest object.
Parameters
webAddresstext: The web address for the object.
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetWebAddress("https://quorumlanguage.com/GETtest.php")
output request:GetWebAddress()
end
end