MyChat Scripts Engine: mHTTPSendPostMessage
Sending POST queries over the network. HTTP/HTTPS are supported.
Syntax
function mHTTPSendPostMessage(sURL, sBody, 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/). |
sBody |
string |
query body. Text string; |
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
var
sResult, sJSON: string;
begin
sJSON := '{}';
JSONSetString(sJSON, 'cmd', '0002');
JSONSetInteger(sJSON, 'UserTo', 6);
JSONSetInteger(sJSON, 'UserFrom', 3);
JSONSetString(sJSON, 'Msg', 'Hit the road Jack' + CRLF +
'and don''t you come back' + CRLF +
'no more, no more, no more, no more.');
JSONSetString(sJSON, 'APIStype', 'msl');
JSONSetString(sJSON, 'ServerKey', 'iddqd');
mLogScript(sJSON, 'request');
sResult := mHTTPSendPostMessage('https://mychatserver.mycompany.com/API/', sJSON, 'integrationapi: mychat', 2000);
mLogScript(sResult, 'response');
end.
Script work result
[16:41:35] (Log "PostRequestExample"): [request] {"cmd":"0002","Msg":"Hit the road Jack\r\nand don't you come back\r\nno more, no more, no more, no more.","ServerKey":"iddqd","UserFrom":3,"APIStype":"msl","UserTo":6}
[16:41:35] (Log "PostRequestExample"): [response] {"Cmd":2,"UINTo":6,"hash":"qQC3Qn4SMAdgQx5","State":0}
[16:41:35] (Run "PostRequestExample"): Script operation time: 133 ms
[16:41:35] (Run "PostRequestExample"): Script done successfully.
MyChat and its IntegrationAPI (REST) were chosen for the test. The user received the message directly in the chat.
See also
Description of IntegrationAPI commands
Created with the Personal Edition of HelpNDoc: Effortlessly Support Your Windows Applications with HelpNDoc's CHM Generation