-
Notifications
You must be signed in to change notification settings - Fork 4
Usage
With the new version 0.8 there is a completely new system. Now ArmA3URLFetch uses parameters of the callExtension
command.
At version 0.8 there exists 3 parameters:
-
#url
which is the url of the request -
#method
which is the request method (like GET, POST, e.g.) and -
#jsonToArray
which is converts an JSON result (of for example from an API) to an ArmA 3 array. This array can be parsed byparseSimpleArray
and can further be selected by the functiona3uf_json_fnc_get
(more in the wiki).
For more information visit Parameters
There are two types of requests in ArmA3URLFetch available.
First of all there is the normal request, which is basically just a simple url request.
And there is the client request, which is an extended version of the normal request. With the client request it is possible to set HTTP headers and default client settings.
You can realize this two request types within two ways, either by manually writing a script or by using our predefined SQF functions.
In the following examples, we list examples of both ways.
A simple request can be accomplished by calling our simple request function a3uf_common_fnc_request
.
private _response = [
<string/url>, //the url of an request
<string/method>, //the HTTP method; most of the time it is "GET"
<array/params>, //(optional) parameters of the url request
<bool/decodeJson> //(optional) should a json response converted?
] call a3uf_common_fnc_request;
But you can also do a manual request. But before creating a manual request, please read the following page.
private _res = "arma3urlfetch" callExtension [
"SENDRQ",
[
"#url=<string/url>",
"#method=<string/method>"
]
];
//_res = [<string/requestid>, <int/statusCode>, <int/errorCode>];
_res = "arma3urlfetch" callExtension [
"GETRQ",
[
"<int/requestid>"
]
];
//_res = [<string/urlResponse>, <int/statusCode>, <int/errorCode>];
waitUntil
{
uiSleep 0.1;
_res = "arma3urlfetch" callExtension [
"GETRQ",
[
"<int/requestid>"
]
];
((_res select 1) != 602);
};
_res;
//_res = [<string/urlResponse>, <int/statusCode>, <int/errorCode>];
This might be a way of using this extension for a simple request.
Simply call the following command to add a user:
private _cliendid = [
<string/url>,
<string/method>,
<array/parameters>,
<bool/decodeJson>
] call a3uf_common_fnc_addClient;
You now should have a clientid.
You can optionally set the parameters again or the headers:
[
<int/clientid>,
<array/parameters>
] call a3uf_common_fnc_setClientParameters;
[
<int/clientid>,
<array/headers>
] call a3uf_common_fnc_setClientHeaders;
After you've done this, you can continue using a simple client request:
private _response = [
<int/clientid>
] call a3uf_common_fnc_clientRequest;
Done!
The first step you have to do is to create a new client (please read this page) first, to know which parameters you can use.
private _res = "arma3urlfetch" callExtension [
"ADDCLI",
[
"#url=<string/url>",
"#method=<string/method>"
]
];
//_res = [<string/clientid>, <int/statusCode>, <int/errorCode>];
Once you got the clientid of the newly created client, you can optionally set the parameters again or set the headers for a request.
private _res = "arma3urlfetch" callExtension [
"SETCLIP",
[
"#clientid=<int/clientid>",
<string/params_n>,
...
]
];
//_res = [<string/clientid>, <int/statusCode>, <int/errorCode>];
private _res = "arma3urlfetch" callExtension [
"SETCLIH",
[
"#clientid=<int/clientid>",
<string/headers_n>,
...
]
];
//_res = [<string/clientid>, <int/statusCode>, <int/errorCode>];
After you've done this, you can simply call a request with pre-set parameters.
You also can call it multiple time.
private _response = [
<int/clientid>
] call a3uf_common_fnc_clientRequest;
Thats it.