创建 ABL 客户端以使用 REST Web 服务
Creating ABL Client to Consume a REST Web Service
我没有找到任何关于从 progress 连接到 REST Web 服务的文档。有人可以指出文档的方向或提供连接示例吗?
进度:11.3
从 11.5.1 开始,内置了对以受控方式使用 REST 网络服务的支持。但是因为你不在那个版本上,所以我暂时。
除非升级是一个选项,否则您可以做几件事:
为 HTTP 调用 OS 程序,如 curl 或 wget
具体如何操作取决于选择的实用程序、os、版本等。另请注意,os 更新可能会改变行为。
此外,您还应该在执行此操作之前查看错误重定向等。调用 OS 将创建第二个进程,因此它可能会影响系统资源。仅在您考虑到 ose 的情况下使用。
另一方面,它既简单又快速。 Curl 也非常灵活,可以帮助 headers 或您可能想使用的其他东西。
您也可以考虑直接调用 curl 库。请注意,在这种情况下,您将严重依赖内存指针和其他 c-like 结构!
PROCEDURE curl:
DEFINE INPUT PARAMETER pcUrl AS CHARACTER NO-UNDO.
DEFINE OUTPUT PARAMETER pcResponse AS LONGCHAR NO-UNDO.
DEFINE VARIABLE cCommand AS CHARACTER NO-UNDO.
/* -s is for silent use - show no errors or feedback on the screen */
cCommand = "curl -s " + pcUrl + " > /tmp/curl.txt".
OS-COMMAND NO-CONSOLE VALUE(cCommand).
COPY-LOB FROM FILE "/tmp/curl.txt" TO pcResponse .
END.
DEFINE VARIABLE lc AS LONGCHAR NO-UNDO.
run curl("http://www.google.com/", OUTPUT lc).
MESSAGE STRING(SUBSTRING(lc,1,100)) VIEW-AS ALERT-BOX.
使用.net 类
我不了解 .net,因此我无法帮助您编写代码。您将不得不研究如何在 .Net 中调用网络服务,然后 "translate" 进入 ABL。这仅适用于 Windows - Progress 不支持 Mono 或其他 OSes 中的其他 .net 方式。
使用套接字自己滚动
无耻地偷来的例子来自:Progress Knowledgebase。
DEFINE VARIABLE vcHost AS CHARACTER INITIAL "localhost" NO-UNDO.
DEFINE VARIABLE vcPort AS CHARACTER INITIAL "8080" NO-UNDO.
DEFINE VARIABLE vhSocket AS HANDLE NO-UNDO.
CREATE SOCKET vhSocket.
vhSocket:CONNECT('-H ' + vcHost + ' -S ' + vcPort) NO-ERROR.
IF vhSocket:CONNECTED() = FALSE THEN
DO:
MESSAGE "Connection failure" VIEW-AS ALERT-BOX.
MESSAGE ERROR-STATUS:GET-MESSAGE(1) VIEW-AS ALERT-BOX.
RETURN.
END.
ELSE
MESSAGE "Connect"
VIEW-AS ALERT-BOX.
vhSocket:SET-READ-RESPONSE-PROCEDURE('getResponse').
/* supposes there is an webspeed app called yourapp.w that receives param1, param2, param3 */
RUN PostRequest (
INPUT '/scripts/cgiip.exe/WService=wsbroker1/yourApp.w',
INPUT 'param1=value¶m2=value¶m3=value'
).
WAIT-FOR READ-RESPONSE OF vhSocket.
vhSocket:DISCONNECT() NO-ERROR.
DELETE OBJECT vhSocket.
QUIT.
PROCEDURE getResponse:
DEFINE VARIABLE vcWebResp AS CHARACTER NO-UNDO.
DEFINE VARIABLE lSucess AS LOGICAL NO-UNDO.
DEFINE VARIABLE mResponse AS MEMPTR NO-UNDO.
IF vhSocket:CONNECTED() = FALSE THEN do:
MESSAGE 'Not Connected' VIEW-AS ALERT-BOX.
RETURN.
END.
lSucess = TRUE.
DO WHILE vhSocket:GET-BYTES-AVAILABLE() > 0:
SET-SIZE(mResponse) = vhSocket:GET-BYTES-AVAILABLE() + 1.
SET-BYTE-ORDER(mResponse) = BIG-ENDIAN.
vhSocket:READ(mResponse,1,1,vhSocket:GET-BYTES-AVAILABLE()).
vcWebResp = vcWebResp + GET-STRING(mResponse,1).
END.
/*
*PUT HERE THE CODE TO MANIPULATE THE ANSWER
*/
END.
PROCEDURE PostRequest:
DEFINE VARIABLE vcRequest AS CHARACTER.
DEFINE VARIABLE mRequest AS MEMPTR.
DEFINE INPUT PARAMETER postUrl AS CHAR.
/* URL that will send the data. It must be all the path after the server. IE:/scripts/cgiip.exe/WService=wsbroker1/myApp.htm */
DEFINE INPUT PARAMETER postData AS CHAR.
/* Parameters to be sent in the format paramName=value¶mName=value¶mName=value */
vcRequest =
'POST ' +
postUrl +
' HTTP/1.0~r~n' +
'Content-Type: application/x-www-form-urlencoded~r~n' +
'Content-Length:' + string(LENGTH(postData)) +
'~r~n' + '~r~n' +
postData + '~r~n'.
MESSAGE vcREquest
VIEW-AS ALERT-BOX.
SET-SIZE(mRequest) = 0.
SET-SIZE(mRequest) = LENGTH(vcRequest) + 1.
SET-BYTE-ORDER(mRequest) = BIG-ENDIAN.
PUT-STRING(mRequest,1) = vcRequest .
vhSocket:WRITE(mRequest, 1, LENGTH(vcRequest)).
END PROCEDURE.
我没有找到任何关于从 progress 连接到 REST Web 服务的文档。有人可以指出文档的方向或提供连接示例吗?
进度:11.3
从 11.5.1 开始,内置了对以受控方式使用 REST 网络服务的支持。但是因为你不在那个版本上,所以我暂时。
除非升级是一个选项,否则您可以做几件事:
为 HTTP 调用 OS 程序,如 curl 或 wget
具体如何操作取决于选择的实用程序、os、版本等。另请注意,os 更新可能会改变行为。
此外,您还应该在执行此操作之前查看错误重定向等。调用 OS 将创建第二个进程,因此它可能会影响系统资源。仅在您考虑到 ose 的情况下使用。
另一方面,它既简单又快速。 Curl 也非常灵活,可以帮助 headers 或您可能想使用的其他东西。
您也可以考虑直接调用 curl 库。请注意,在这种情况下,您将严重依赖内存指针和其他 c-like 结构!
PROCEDURE curl:
DEFINE INPUT PARAMETER pcUrl AS CHARACTER NO-UNDO.
DEFINE OUTPUT PARAMETER pcResponse AS LONGCHAR NO-UNDO.
DEFINE VARIABLE cCommand AS CHARACTER NO-UNDO.
/* -s is for silent use - show no errors or feedback on the screen */
cCommand = "curl -s " + pcUrl + " > /tmp/curl.txt".
OS-COMMAND NO-CONSOLE VALUE(cCommand).
COPY-LOB FROM FILE "/tmp/curl.txt" TO pcResponse .
END.
DEFINE VARIABLE lc AS LONGCHAR NO-UNDO.
run curl("http://www.google.com/", OUTPUT lc).
MESSAGE STRING(SUBSTRING(lc,1,100)) VIEW-AS ALERT-BOX.
使用.net 类
我不了解 .net,因此我无法帮助您编写代码。您将不得不研究如何在 .Net 中调用网络服务,然后 "translate" 进入 ABL。这仅适用于 Windows - Progress 不支持 Mono 或其他 OSes 中的其他 .net 方式。
使用套接字自己滚动
无耻地偷来的例子来自:Progress Knowledgebase。
DEFINE VARIABLE vcHost AS CHARACTER INITIAL "localhost" NO-UNDO.
DEFINE VARIABLE vcPort AS CHARACTER INITIAL "8080" NO-UNDO.
DEFINE VARIABLE vhSocket AS HANDLE NO-UNDO.
CREATE SOCKET vhSocket.
vhSocket:CONNECT('-H ' + vcHost + ' -S ' + vcPort) NO-ERROR.
IF vhSocket:CONNECTED() = FALSE THEN
DO:
MESSAGE "Connection failure" VIEW-AS ALERT-BOX.
MESSAGE ERROR-STATUS:GET-MESSAGE(1) VIEW-AS ALERT-BOX.
RETURN.
END.
ELSE
MESSAGE "Connect"
VIEW-AS ALERT-BOX.
vhSocket:SET-READ-RESPONSE-PROCEDURE('getResponse').
/* supposes there is an webspeed app called yourapp.w that receives param1, param2, param3 */
RUN PostRequest (
INPUT '/scripts/cgiip.exe/WService=wsbroker1/yourApp.w',
INPUT 'param1=value¶m2=value¶m3=value'
).
WAIT-FOR READ-RESPONSE OF vhSocket.
vhSocket:DISCONNECT() NO-ERROR.
DELETE OBJECT vhSocket.
QUIT.
PROCEDURE getResponse:
DEFINE VARIABLE vcWebResp AS CHARACTER NO-UNDO.
DEFINE VARIABLE lSucess AS LOGICAL NO-UNDO.
DEFINE VARIABLE mResponse AS MEMPTR NO-UNDO.
IF vhSocket:CONNECTED() = FALSE THEN do:
MESSAGE 'Not Connected' VIEW-AS ALERT-BOX.
RETURN.
END.
lSucess = TRUE.
DO WHILE vhSocket:GET-BYTES-AVAILABLE() > 0:
SET-SIZE(mResponse) = vhSocket:GET-BYTES-AVAILABLE() + 1.
SET-BYTE-ORDER(mResponse) = BIG-ENDIAN.
vhSocket:READ(mResponse,1,1,vhSocket:GET-BYTES-AVAILABLE()).
vcWebResp = vcWebResp + GET-STRING(mResponse,1).
END.
/*
*PUT HERE THE CODE TO MANIPULATE THE ANSWER
*/
END.
PROCEDURE PostRequest:
DEFINE VARIABLE vcRequest AS CHARACTER.
DEFINE VARIABLE mRequest AS MEMPTR.
DEFINE INPUT PARAMETER postUrl AS CHAR.
/* URL that will send the data. It must be all the path after the server. IE:/scripts/cgiip.exe/WService=wsbroker1/myApp.htm */
DEFINE INPUT PARAMETER postData AS CHAR.
/* Parameters to be sent in the format paramName=value¶mName=value¶mName=value */
vcRequest =
'POST ' +
postUrl +
' HTTP/1.0~r~n' +
'Content-Type: application/x-www-form-urlencoded~r~n' +
'Content-Length:' + string(LENGTH(postData)) +
'~r~n' + '~r~n' +
postData + '~r~n'.
MESSAGE vcREquest
VIEW-AS ALERT-BOX.
SET-SIZE(mRequest) = 0.
SET-SIZE(mRequest) = LENGTH(vcRequest) + 1.
SET-BYTE-ORDER(mRequest) = BIG-ENDIAN.
PUT-STRING(mRequest,1) = vcRequest .
vhSocket:WRITE(mRequest, 1, LENGTH(vcRequest)).
END PROCEDURE.