open.mapquestapi.com上的Progress 4GL GET请求
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了open.mapquestapi.com上的Progress 4GL GET请求相关的知识,希望对你有一定的参考价值。
我有一个严重的问题,正确的GET方法调用open.mapquestapi.com来获取一些地理定位数据。我的代码非常标准,主要来自Progress KB和其他网站。
DEFINE VARIABLE vcHost AS CHARACTER INITIAL "open.mapquestapi.com" NO-UNDO.
DEFINE VARIABLE vcPort AS CHARACTER INITIAL "80" NO-UNDO.
DEFINE VARIABLE vhSocket AS HANDLE NO-UNDO.
CREATE SOCKET vhSocket.
vhSocket:CONNECT('-H ' + vcHost + ' -S 80')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.
这部分代码返回消息“Connect”,所以我相信我已正确连接。下一部分:
vhSocket:SET-READ-RESPONSE-PROCEDURE('getResponse').
RUN GetRequest.
WAIT-FOR READ-RESPONSE OF vhSocket.
vhSocket:DISCONNECT() NO-ERROR.
DELETE OBJECT vhSocket.
QUIT.
PROCEDURE GetRequest:
DEFINE VARIABLE vcRequest AS CHARACTER.
DEFINE VARIABLE mRequest AS MEMPTR.
vcRequest = 'GET ' +
'/nominatim/v1' +
'/search.php?key=WLrMQcGao56Cb5m4ulmwZZDOegO3BkZn&format=xml&q=warszawa chałubińskiego 8&addressdetails=1&limit=50' +
" ~r~n HTTP/1.1 ~r~n" +
"~r~nConnection: close~r~n~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.
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.
message vcWebResp view-as alert-box.
END.
来自Web服务器的响应是:HTTP / 1.1 400 BAD REQUEST内容长度:0连接:关闭
正如您所看到的,大部分代码都来自Internet上的Progress文档和示例。我尝试以各种方式修改我的GET请求,但没有运气。我也尝试了一些不同的代码,但我认为一个是正确解决方案的指南。预期结果应该像在这个网站上:Geo location request。有关此API的一些简短文档可以在HERE找到。此代码将在UNIX服务器上运行,因此我无法使用.NET库。任何帮助将不胜感激。
编辑:请记住关键参数中显示的哈希值将很快被删除!你应该在business.mapquest.com上免费生成自己的密钥。
假设您使用的是最新版本的Progress OpenEdge(11.5+),您可以使用OpenEdge.Net.pl(也可在Unix上使用)创建请求,以下(在Linux上运行)可以帮助您入门:
https://abldojo.services.progress.com:443/#/?shareId=5b9064d6689ac207d7375047
USING OpenEdge.Net.HTTP.RequestBuilder.
USING OpenEdge.Net.HTTP.ClientBuilder.
USING OpenEdge.Net.HTTP.IHttpRequest.
USING OpenEdge.Net.HTTP.IHttpResponse.
USING Progress.Json.ObjectModel.JsonArray.
define variable oRequest as IHttpRequest no-undo.
define variable oResponse as IHttpResponse no-undo.
define variable oEntity as Progress.Lang.Object no-undo.
oRequest = RequestBuilder
:Get(
"http://open.mapquestapi.com"
+ "/nominatim/v1/search.php"
+ "?key=WLrMQcGao56Cb5m4ulmwZZDOegO3BkZn"
+ "&q=warszawa chałubińskiego 8"
+ "&addressdetails=1"
+ "&limit=50"
+ "&format=json"
)
:Request
.
oResponse = ClientBuilder:Build():Client:Execute( oRequest ).
oEntity = oResponse:Entity.
def var lcc as longchar no-undo.
cast( oEntity, JsonArray ):Write( lcc, true ).
message string( lcc ).
OpenEdge.Net.pl也只是使用ABL代码和套接字进行通信。
以上是关于open.mapquestapi.com上的Progress 4GL GET请求的主要内容,如果未能解决你的问题,请参考以下文章
Flash Pro cc 为啥我手机上的舞台宽度和高度设置为Flash pro里面的?
Microsoft Windows 7 Pro 上的实时应用程序