47 lines
1.3 KiB
Plaintext
47 lines
1.3 KiB
Plaintext
OPTIONS SHORT CIRCUIT
|
|
IMPORT com
|
|
|
|
#
|
|
## Communications library using com (http or https)
|
|
#
|
|
|
|
FUNCTION sync_send_command(url, cmd)
|
|
|
|
DEFINE url, cmd STRING
|
|
DEFINE result, tmp STRING
|
|
DEFINE http_req com.HTTPRequest
|
|
DEFINE http_resp com.HTTPResponse
|
|
|
|
DISPLAY "sync_send_command -> url=",url
|
|
|
|
TRY
|
|
LET http_req = com.HTTPRequest.Create(url)
|
|
CALL http_req.setConnectionTimeout(10)
|
|
CALL http_req.setTimeout(20)
|
|
CALL http_req.setMethod("POST")
|
|
CALL http_req.setCharset("UTF-8")
|
|
CALL http_req.setHeader("DBSync-Client","mbs")
|
|
CALL http_req.setHeader("Content-Type","dbsync/json")
|
|
CALL http_req.doTextRequest(cmd)
|
|
LET http_resp=http_req.getResponse()
|
|
IF http_resp.getStatusCode() != 200 THEN
|
|
RETURN http_resp.getStatusCode(), http_resp.getStatusDescription()
|
|
END IF
|
|
LET tmp = http_resp.getStatusDescription()
|
|
IF (tmp == "OK" || tmp == "no error" ) THEN
|
|
RETURN -1, SFMT("HTTP request status description: %1 ",tmp)
|
|
END IF
|
|
LET result = http_resp.getTextResponse()
|
|
CATCH
|
|
RETURN -2, SFMT("HTTP request error: STATUS=%1 (%2)",STATUS,SQLCA.SQLERRM)
|
|
END TRY
|
|
|
|
RETURN 0, result
|
|
|
|
END FUNCTION
|
|
|
|
FUNCTION show_sync_err(msg)
|
|
DEFINE msg STRING
|
|
CALL fgl_winmessage(%"ERROR", msg, "exclamation")
|
|
END FUNCTION
|