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

Duvida Passar chave de ambiente via REST

Discussão em 'Progress 4GL' iniciado por Lucas do Carvalhal Sergio, Setembro 2, 2024.

  1. Lucas do Carvalhal Sergio

    Lucas do Carvalhal Sergio Sem Pontuação

    Bom dia, estou tentando fazer uma comunicação via REST mas ao conseguir estabelecer a comunicação está dando erro que "Está faltando a chave do ambiente". Não estou sabendo como passar essa chave.
    Na verdade é meu primeiro programa dessa forma e estou estudando e pesquisando para fazer funcionar, evolui bastante, mas nesse ponto não consegui resolver.
    O oResponse:StatusCode que recebo é o 200, como se estivesse ok a comunicação sem erros. Mas o retorno que falta a chave do ambiente. Passei a chave na oCredentials = new Credentials('chave-ambiente', 'usuario', 'senha') mas sem sucesso.


    USING Progress.Lang.Object.
    USING OpenEdge.Core.WidgetHandle.
    USING OpenEdge.Core.String.
    USING OpenEdge.Net.HTTP.Credentials.
    USING OpenEdge.Net.HTTP.RequestBuilder.
    USING OpenEdge.Net.HTTP.IHttpRequest.
    USING OpenEdge.Net.HTTP.IHttpResponse.
    USING OpenEdge.Net.HTTP.ClientBuilder.
    USING Progress.Json.ObjectModel.JsonObject.
    USING Progress.Json.ObjectModel.ObjectModelParser.
    USING Progress.Lang.Object.
    //using OpenEdge.Net.URI.

    DEFINE VARIABLE hXmlDoc AS HANDLE NO-UNDO.
    DEFINE VARIABLE oCredentials AS Credentials NO-UNDO.
    DEFINE VARIABLE httpUrl AS CHARACTER NO-UNDO.
    DEFINE VARIABLE lcHTML AS LONGCHAR NO-UNDO.
    DEFINE VARIABLE oEntity AS Object NO-UNDO.
    DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO.
    DEFINE VARIABLE oResponse AS IHttpResponse NO-UNDO.

    DEFINE VARIABLE oJson AS JsonObject NO-UNDO.


    httpUrl = "https://api.desk.ms/Login/autenticar".

    oCredentials = new Credentials('chave-ambiente', 'usuario', 'senha').

    oRequest = RequestBuilder:Get(httpUrl)
    :AcceptJson()
    :UsingBasicAuthentication(oCredentials)
    :Request.

    oResponse = ClientBuilder:Build():Client:Execute(oRequest).
    oEntity = oResponse:Entity.

    MESSAGE
    oResponse:StatusCode SKIP
    oResponse:StatusReason SKIP
    oResponse:ContentType SKIP
    oResponse:Entity:ToString()
    VIEW-AS ALERT-BOX.

    IF TYPE-OF(oEntity, JsonObject) THEN
    CAST(oEntity, JsonObject):WriteFile('c:\temp/entity.json', true).
    ELSE
    IF TYPE-OF(oEntity, WidgetHandle) THEN
    DO:
    hXmlDoc = CAST(oEntity, WidgetHandle):Value.
    hXmlDoc:save('file', 'c:\temp/entity.xml').
    END.
    ELSE
    DO:
    IF TYPE-OF(oEntity, String) THEN
    lcHTML = CAST(oEntity, String):Value.
    ELSE
    lcHTML = oEntity:ToString().

    /* Change extension per the Response's ContentType */
    CASE oResponse:ContentType:
    WHEN 'application/json' THEN
    COPY-LOB lcHTML TO FILE 'c:\temp/entity.json'.
    WHEN 'text/html' THEN
    COPY-LOB lcHTML TO FILE 'c:\temp/entity.html'.
    OTHERWISE
    COPY-LOB lcHTML TO FILE 'c:\temp/entity.txt'.
    END CASE.
    END.
  2. rafael.andrade

    rafael.andrade Membro Master Moderador Equipe de Suporte

    Tu já testou no Postman?

Compartilhe esta Página