I do some tests with the WebClient FB's from CODESYS IIoT libraries. In this tests I interact with the ctrlX CORE itself. I'm able to read (GET) data and also to get (POST) the Bearer token:
GET to get the type plate from CORE (sURL:= 'https://127.0.0.1/system/api/v1/typeplate')
POST to get the Bearer token (sURL:= 'https://127.0.0.1/identity-manager/api/v1/auth/token')
But I'm not able to write (PUT) data. I would like to write a datalayer variable, but I get always the error 400 Bad Request:
This is my declaration:Â
wsPOSTCommand : WSTRING(511);
wsBEARERToken : WSTRING(1024);
fbWebClientPUT: WEB_CLIENT.WebClient;Â
This is my code:
wsPOSTCommand := "{$"type$": $"uint32$", $"value$": 99}";
wsBEARERToken := "{$"Authorization$": $"Bearer eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MTIxODc1ODYsImlhdCI6MTcxMjE1ODc4NiwiaWQiOiIxMDAwIiwibmFtZSI6ImJvc2NocmV4cm90aCIsIm5vbmNlIjoiMTBjNjRhNTUtNmQxZC00NjU3LTk1ZWEtMWY1ZDY4MmNkODU3IiwicGxjaGFuZGxlIjozMTY5NDc3OTA1MjM0NTE3MjYsInJlbW90ZWF1dGgiOiIiLCJzY29wZSI6WyJyZXhyb3RoLWRldmljZS5hbGwucnd4Il19.CcZ1xZnvTRY0r3f-rjJLo7BEAGJif9wDlNHYO7USYUboZmMlLkjrgI6zuA2J8XAg1CuB8wtEAOLQRZLXjLlQbyJICF5wD6eE8ff4Xu59A149hBKC6m77JD82FPkRHDNH$"}";
// try to use a PUT command
fbWebClientPUT(
xExecute := ,
udiTimeOut := 1000000,
sURL := 'https://127.0.0.1/automation/api/v2/nodes/plc/app/Application/sym/GVL_Datalayer/dwTestDWORD',
eRequestType := WEB_CLIENT.REQUEST_TYPE.PUT,
eContentType := WEB_CLIENT.CONTENT_TYPE.APPLICATION_JSON,
pwsAdditionalHeader := ADR(wsBEARERToken),
pwsPostValue := ADR(wsPOSTCommand),
xCloseConnection := ,
hCert := ,
itfTLSContext := ,
itfAsyncProperty := ,
xDone => ,
xBusy => ,
xError => ,
eError => ,
httpResult => );Â
Â
Â