1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Progress 4GL GET request on open.mapquestapi.com

Discussão em 'StackOverflow' iniciado por fdantas, Setembro 5, 2018.

  1. fdantas

    fdantas Administrator Moderador

    I have a serious problem with proper GET method calling on open.mapquestapi.com to get some geolocation data. My code is quite standard, mostly taken from Progress KB and other sites.

    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.


    This part of code returns message "Connect" so I believe I'm properly connected. Next part:

    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.


    Resposne from webserver is: HTTP/1.1 400 BAD_REQUEST Content-Length: 0 Connection: Close

    As You can see most of the code is taken from Progress docs and samples found in internet. I tried to modify my GET request in various ways but without luck. I also tried some differnet code, but I think that one is guides to proper solution. Expected result should be like on this site: Geo location request. Some short documentation about this API can be found HERE. This code will be running on UNIX server so I can't use .NET libraries. Any help will be appreciated.

    Continue reading...

Compartilhe esta Página