MyChat Scripts Engine: mHTTPSendGetMessage
Sending GET queries over the network. HTTP/HTTPS are supported.
Syntax
function mHTTPSendGetMessage(sURL, sHeaders: string; iTimeOut: integer): string;
Parameters and return values
Parameter |
Type |
Value |
sURL |
string |
address, where you have to send the query. http and https are supported. You can specify any port for connection (for example, http://yourserver.com:8080/myservice/). |
sHeaders |
string |
special headers (if necessary). CRLF can be separated, if you need more than one (an empty string, if the service does not require this feature); |
iTimeOut |
integer |
time in milliseconds, the maximum time for command sending. |
Function result
Returns the response to the query as a text string. If the query was unsuccessful, the function returns an empty string or the network error text.
Example
Connecting to the service zadarma.com to check the account balance:
const
sParam = '';
sMethod = '/v1/info/balance/';
sKey = '1ba738452343797198';
sSecret = '7f984576e664';
var
sJSONResult, sSign, status: string;
begin
sSign := EncodeBase64(StrToHex(HMAC_SHA1(sMethod + sParam + StrToHex(MD5(sParam)), sSecret)));
sJSONResult := mHTTPSendGetMessage('https://api.zadarma.com' + sMethod, 'Authorization:' + sKey + ':' + sSign, 1000);
mLogScript(sJSONResult, 'sJSONResult');
JSONGetString(sJSONResult, 'status', status);
mLogScript(status, 'status');
end.
Script work result
[16:33:03] (Log "mHTTPSendGetMessage"): [sJSONResult] {"status":"success","balance":10.2637,"currency":"USD"}
[16:33:03] (Log "mHTTPSendGetMessage"): [status] success
[16:33:03] (Run "mHTTPSendGetMessage"): Script operation time: 565 ms
[16:33:03] (Run "mHTTPSendGetMessage"): Script done successfully.