Libraries.Network.NetworkRequest Documentation
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
Inherits from: Libraries.Language.Object
Actions Documentation
AddHeader(text key, text value)
This method adds a header to a NetworkRequest object.
Parameters
- text key: The name of the header
- text value: 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
- text value: The unformatted string.
Return
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
Compare(Libraries.Language.Object object)
This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.
Parameters
- Libraries.Language.Object: The object to compare to.
Return
integer: The Compare result, Smaller, Equal, or Larger.
Example
Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)
Equals(Libraries.Language.Object object)
This action determines if two objects are equal based on their hash code values.
Parameters
- Libraries.Language.Object: The to be compared.
Return
boolean: True if the hash codes are equal and false if they are not equal.
Example
use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)
FormEncodeData(Libraries.Data.Formats.JavaScriptObjectNotation data)
This method is used to url encode a text value from a JavaScriptObjectNotation.
Parameters
- Libraries.Data.Formats.JavaScriptObjectNotation: A JavaScriptObjectNotation object to encode.
Return
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
- Libraries.Containers.HashTable: A HashTable containing key value pairs to encode.
Return
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.
Return
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.
Return
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.
Return
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.
Return
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.
Return
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.
Return
Example
use Libraries.Network.NetworkRequest
class Main
action Main
NetworkRequest request
request:SetDownloadFile("logo.png")
output request:GetDownloadFile():GetAbsolutePath()
end
end
GetHashCode()
This action gets the hash code for an object.
Return
integer: The integer hash code of the object.
Example
Object o
integer hash = o:GetHashCode()
GetHeaders()
This method gets a HashTable of the headers of a NetworkRequest object.
Return
Libraries.Containers.HashTable: 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.
Return
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.
Return
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.
Return
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.
Return
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.
Return
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.
Return
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
- text data: 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
- integer chunkLength: 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
- boolean value: 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
- integer milliseconds: 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
- boolean value: 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
- boolean value: 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
- Libraries.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
- text downloadFile: 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
- boolean value: 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
- integer milliseconds: 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