我找不到任何有关从进度连接到REST Web服务的文档。有人可以指出我的文档方向或提供连接示例。
进展:11.3
答案 0 :(得分:5)
从11.5.1开始,内置支持以受控方式使用REST Web服务。但是,由于你没有使用该版本,我现在将其留下 。
除非升级是一个选项,否则你可以做几件事:
调用HTTP程序,如curl或wget
如何做到这一点将取决于选择,操作系统,版本等的实用程序。另外请注意,操作系统更新可能会改变行为。
此外,您应该在执行此操作之前查看错误重定向等。调用操作系统将创建第二个进程,因此可能会影响系统资源。仅在您考虑这些事情时使用。
另一方面,它简单快捷。 Curl也非常灵活,可以帮助您使用任何标题或其他东西。
您也可以直接调用curl库。请注意,在这种情况下,你将严重依赖于mempointers和其他类似c的结构!
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中调用webservices开始,然后“转换”为ABL。这只适用于Windows - Progress不支持Mono或其他操作系统在其他操作系统中执行.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.