• Get dafrom API REST (method GET)

    From =?UTF-8?Q?Sebasti=C3=A1n_BASSANO?=@21:1/5 to All on Fri Dec 24 07:02:23 2021
    Hi, i'm trying to consume API REST from VO.
    For example:

    https://test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD

    returns

    ["Error de autenticaci\u00f3n (2) USER"]

    but from VO i always get empty response.
    I try:

    Option 1
    cRequest:= "authUser=USER&authPass=PASSWORD"
    oHttpSession:= CHttp{"SENASA.APIREST"}
    IF oHttpSession:ConnectRemote("http://test.senasa.gov.ar")
    IF oHttpSession:OpenRequest("GET", "/agrotraza/src/api/Consulta_Tipo_Envase", INTERNET_FLAG_RELOAD + INTERNET_FLAG_KEEP_CONNECTION)
    IF oHttpSession:SendRequest(NULL_STRING, PTR(_CAST, cRequest), SLen(cRequest))
    cResponse:= oHttpSession:GetResponse()
    InfoBox{SELF, "1.Response", cResponse}:Show()
    ELSE
    WarningBox{SELF, "1.Error.1", oHttpSession:ErrorMsg}:Show()
    ENDIF
    oHttpSession:CloseRequest()
    ELSE
    WarningBox{SELF, "1.Error.2", oHttpSession:ErrorMsg}:Show()
    ENDIF
    oHttpSession:CloseRemote()
    oHttpSession:= NULL_OBJECT
    ELSE
    WarningBox{SELF, "1.Error.3", oHttpSession:ErrorMsg}:Show()
    ENDIF

    Option 2
    oHttpSession:= CHttp{"SENASA.APIREST", 443}
    IF oHttpSession:ConnectRemote("https://test.senasa.gov.ar")
    IF oHttpSession:OpenRequest("GET", "/agrotraza/src/api/Consulta_Tipo_Envase", INTERNET_FLAG_RELOAD + INTERNET_FLAG_KEEP_CONNECTION + INTERNET_FLAG_SECURE)
    IF oHttpSession:SendRequest(NULL_STRING, PTR(_CAST, cRequest), SLen(cRequest))
    cResponse:= oHttpSession:GetResponse()
    InfoBox{SELF, "2.Response", cResponse}:Show()
    ELSE
    WarningBox{SELF, "2.Error.1", oHttpSession:ErrorMsg}:Show()
    ENDIF
    oHttpSession:CloseRequest()
    ELSE
    WarningBox{SELF, "2.Error.2", oHttpSession:ErrorMsg}:Show()
    ENDIF
    oHttpSession:CloseRemote()
    oHttpSession:= NULL_OBJECT
    ELSE
    WarningBox{SELF, "2.Error.3", oHttpSession:ErrorMsg}:Show()
    ENDIF

    Option 3
    oHttpSession:= CHttp{"SENASA.APIREST"}
    IF oHttpSession:ConnectRemote("test.senasa.gov.ar")
    IF oHttpSession:OpenRequest("GET", "/agrotraza/src/api/Consulta_Tipo_Envase", INTERNET_FLAG_RELOAD + INTERNET_FLAG_KEEP_CONNECTION)
    IF oHttpSession:SendRequest(NULL_STRING, PTR(_CAST, cRequest), SLen(cRequest))
    cResponse:= oHttpSession:GetResponse()
    InfoBox{SELF, "3.Response", cResponse}:Show()
    ELSE
    WarningBox{SELF, "3.Error.1", oHttpSession:ErrorMsg}:Show()
    ENDIF
    oHttpSession:CloseRequest()
    ELSE
    WarningBox{SELF, "3.Error.2", oHttpSession:ErrorMsg}:Show()
    ENDIF
    oHttpSession:CloseRemote()
    oHttpSession:= NULL_OBJECT
    ELSE
    WarningBox{SELF, "3.Error.3", oHttpSession:ErrorMsg}:Show()
    ENDIF

    Option 4
    oHttpSession:= CHttp{"SENASA.APIREST", 443}
    IF oHttpSession:ConnectRemote("test.senasa.gov.ar")
    IF oHttpSession:OpenRequest("GET", "/agrotraza/src/api/Consulta_Tipo_Envase", INTERNET_FLAG_RELOAD + INTERNET_FLAG_KEEP_CONNECTION + INTERNET_FLAG_SECURE)
    IF oHttpSession:SendRequest(NULL_STRING, PTR(_CAST, cRequest), SLen(cRequest))
    cResponse:= oHttpSession:GetResponse()
    InfoBox{SELF, "4.Response", cResponse}:Show()
    ELSE
    WarningBox{SELF, "4.Error.1", oHttpSession:ErrorMsg}:Show()
    ENDIF
    oHttpSession:CloseRequest()
    ELSE
    WarningBox{SELF, "4.Error.2", oHttpSession:ErrorMsg}:Show()
    ENDIF
    oHttpSession:CloseRemote()
    oHttpSession:= NULL_OBJECT
    ELSE
    WarningBox{SELF, "4.Error.3", oHttpSession:ErrorMsg}:Show()
    ENDIF

    Option 5
    oHttpSession:= CHttp{"SENASA.APIREST"}
    IF oHttpSession:ConnectRemote("http://test.senasa.gov.ar")
    cResponse:= oHttpSession:GetDocumentByURL("http://test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD")
    InfoBox{SELF, "5.Response", cResponse}:Show()
    ELSE
    WarningBox{SELF, "5.Error.1", oHttpSession:ErrorMsg}:Show()
    ENDIF
    oHttpSession:CloseRemote()
    oHttpSession:= NULL_OBJECT

    Option 6
    oHttpSession:= CHttp{"SENASA.APIREST", 443}
    IF oHttpSession:ConnectRemote("https://test.senasa.gov.ar")
    cResponse:= oHttpSession:GetDocumentByURL("https://test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD")
    InfoBox{SELF, "6.Response", cResponse}:Show()
    ELSE
    WarningBox{SELF, "6.Error.1", oHttpSession:ErrorMsg}:Show()
    ENDIF
    oHttpSession:CloseRemote()
    oHttpSession:= NULL_OBJECT

    Option 7
    oHttpSession:= CHttp{"SENASA.APIREST"}
    IF oHttpSession:ConnectRemote("test.senasa.gov.ar")
    cResponse:= oHttpSession:GetDocumentByURL("test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD")
    InfoBox{SELF, "7.Response", cResponse}:Show()
    ELSE
    WarningBox{SELF, "7.Error.1", oHttpSession:ErrorMsg}:Show()
    ENDIF
    oHttpSession:CloseRemote()
    oHttpSession:= NULL_OBJECT

    Option 8
    oHttpSession:= CHttp{"SENASA.APIREST", 443}
    IF oHttpSession:ConnectRemote("test.senasa.gov.ar")
    cResponse:= oHttpSession:GetDocumentByURL("test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD")
    InfoBox{SELF, "8.Response", cResponse}:Show()
    ELSE
    WarningBox{SELF, "8.Error.1", oHttpSession:ErrorMsg}:Show()
    ENDIF
    oHttpSession:CloseRemote()
    oHttpSession:= NULL_OBJECT

    Can any help me?
    Regards.
    Sebastián

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From D.J.W. van Kooten@21:1/5 to All on Sat Dec 25 02:18:04 2021
    Replying on message of Fri, 24 Dec 2021 07:02:23 -0800 (PST) from
    Sebastián BASSANO:


    Hello Sebastián

    Hi, i'm trying to consume API REST from VO.
    For example:

    https://test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD

    returns

    ["Error de autenticaci\u00f3n (2) USER"]

    but from VO i always get empty response.


    We've had some trouble REST API's (Sending XML) as well, in the X#
    forum I asked this question:

    https://www.xsharp.eu/forum/public-product/659-rest-service-does-not-work#4634

    I don't recall all details but the main problem eventually was that
    from VO a user name was not used somehow and when the password was
    added directly before the xml (extra key-value-pair in the POST body), something like this, it worked:

    secret=123456&xml= <Root> etc.

    Not sure if this helps you but maybe it's eventually the
    authentication that fails so the result is empty. We got a test URL
    which did not require a login and this returned the right values so we
    knew the authentication was the problem.

    If you would use an X# based DLL, which you can call from VO, you will
    have more logical (.Net) code and many more samples and you will
    probably solve it faster.

    Dick

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Sebasti=C3=A1n_BASSANO?=@21:1/5 to All on Sun Dec 26 08:17:05 2021
    El Friday, December 24, 2021 a la(s) 10:18:07 PM UTC-3, D.J.W. van Kooten escribió:
    Replying on message of Fri, 24 Dec 2021 07:02:23 -0800 (PST) from
    Sebastián BASSANO:


    Hello Sebastián
    Hi, i'm trying to consume API REST from VO.
    For example:

    https://test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD

    returns

    ["Error de autenticaci\u00f3n (2) USER"]

    but from VO i always get empty response.
    We've had some trouble REST API's (Sending XML) as well, in the X#
    forum I asked this question:

    https://www.xsharp.eu/forum/public-product/659-rest-service-does-not-work#4634

    I don't recall all details but the main problem eventually was that
    from VO a user name was not used somehow and when the password was
    added directly before the xml (extra key-value-pair in the POST body), something like this, it worked:

    secret=123456&xml= <Root> etc.

    Not sure if this helps you but maybe it's eventually the
    authentication that fails so the result is empty. We got a test URL
    which did not require a login and this returned the right values so we
    knew the authentication was the problem.

    If you would use an X# based DLL, which you can call from VO, you will
    have more logical (.Net) code and many more samples and you will
    probably solve it faster.

    Dick

    Thanks Dick.
    I'll move to C# and call the code from VO as i do in other oportunities when i got stucked with VO.

    Sebastián

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)