MAMP2 Posted August 7, 2020 Report Share Posted August 7, 2020 Bom dia Pessoal estou precisando ler um arquivo Json para pegar um retorno, e processar dentro do meu sistema, o cliente me mandou isto: Envio: Método: POST URL: http://200.143.189.241:2001/api/segurancas/tokens Parâmetro de envio no body (corpo da requisição): {"NomeUsuario":"nome_usuario_enviado","Senha":"senha_enviada"} Observação: Substituir na String acima, nome_usuario_enviado pelo cpf. Substituir a senha_enviada pela senha enviada. Retorno { "token”: “eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9”} alguem pode me ajudar?, nao sei como fazer pra fazer isto Quote Link to comment Share on other sites More sharing options...
MAMP2 Posted August 7, 2020 Author Report Share Posted August 7, 2020 oi pessoal sobre isto coloquei; oHttp:=TIpClientHttp():new("https://200.143.189.241:2001/api/segurancas/tokens", .F. ) cJson := '{"NomeUsuario":"02615937812","Senha":"tc123456+"}' cRet := "" IF .NOT. oHttp:open() MsgAlert( "Connection error:", oHttp:lastErrorMessage( ) ) ELSE oHttp:Post( cJson) cRet := oHttp:readAll( ) oHttp:close() ENDIF messagebox(0,cRet,"Passou") porem quando roda o o erro : Application =========== Path and name: C:\mot2\mot999.exe (32 bits) Size: 8,448,000 bytes Time from start: 0 hours 0 mins 49 secs Error occurred at: 07/08/2020, 07:26:01 Error description: Error BASE/1081 unsupported protocol: TIPCLIENTHTTP:new() Args: [ 1] = O Object [ 2] = C https Stack Calls =========== Called from: client.prg => TIPCLIENT:NEW(177) Called from: httpcln.prg => TIPCLIENTHTTP:NEW(96) Called from: mot999.prg => BUS_JSON2(33219) Called from: mot999.prg => (b)MENUPRIM(8057) Called from: MENU.PRG => TMENU:COMMAND(0) Called from: WINDOW.PRG => TWINDOW:COMMAND(0) Called from: => TWINDOW:HANDLEEVENT(0) Called from: WINDOW.PRG => _FWH(0) Called from: => WINRUN(0) Called from: WINDOW.PRG => TWINDOW:ACTIVATE(0) Called from: mot999.prg => MAIN(4095) deve estar faltando alguma LIB, é isto?, se for qual á a LIB? Quote Link to comment Share on other sites More sharing options...
EDUTEK Posted August 7, 2020 Report Share Posted August 7, 2020 if !file(mArqXML) mArqXML := cGetFile( "*.xml" , "Selecione o arquivo..." ) endif cXMLDoc := MemoRead(mArqXML) cTipoDoc := LerTag(cXMLDoc,'mod') Try oHttp := CreateObject( 'MSXML2.XMLHTTP' ) Catch oHttp := CreateObject( 'Microsoft.XMLHTTP' ) End oHttp:Open( 'POST', "http://webserver.averba.com.br/rest/Auth", .F. ) oHttp:SetRequestHeader( "Accept","application/json") oHttp:SetRequestHeader( "Content-Type","application/json") oHttp:Send( '{ "usuario": "'+rtrim(lower(mFilUserSeg))+'", "senha": "'+rtrim(lower(mFilPwdSeg))+'", "codigoatm": "'+rtrim(lower(mFilIdSeg))+'" }' ) SysRefresh() cResp := oHttp:ResponseBody cResp := StrTran(cResp,"{","") cResp := StrTran(cResp,"}","") cResp := StrTran(cResp,'"','') cResp := StrTran(cResp,':','') cResp := rtrim(cResp) if cTipoDoc = '57' oHttp:Open( 'POST', "http://webserver.averba.com.br/rest/CTE", .F. ) elseif cTipoDoc = '55' oHttp:Open( 'POST', "http://webserver.averba.com.br/rest/NFE", .F. ) elseif cTipoDoc = '58' oHttp:Open( 'POST', "http://webserver.averba.com.br/rest/MDFE", .F. ) endif oHttp:SetRequestHeader( "Authorization",cResp) oHttp:SetRequestHeader( "Accept","application/xml") oHttp:SetRequestHeader( "Content-Type","application/xml") oHttp:Send( cXMLDoc ) SysRefresh() cRespAverb :=oHttp:ResponseBody if cTipoDoc = '57' cAverba := LerTag(cRespAverb,'NumeroAverbacao') elseif cTipoDoc = '55' cAverba := LerTag(cRespAverb,'NumeroAverbacao') elseif cTipoDoc = '58' cAverba := '' cProtocolo := LerTag(cRespAverb,'Protocolo') endif mNum_averb := respProt := cAverba isso fiz para averbação de CT-e juto a seguradora, acho que é mais ou menos o que vc precisa, faço a conexao, autentico e recebo um token depois com esse token envio o Cte para averbar e pego o retorno da averbação. Quote Link to comment Share on other sites More sharing options...
MAMP2 Posted August 7, 2020 Author Report Share Posted August 7, 2020 é este mesmo amigo, eu deveria pegar este token e usar um get, porem ao buscar o token o campo nao vem, o cResp vem em branco, o que pode ser isto, tem alguma ideia? Quote Link to comment Share on other sites More sharing options...
gilmer Posted August 7, 2020 Report Share Posted August 7, 2020 Boa Tarde, Sugiro fazer testes com o aplicativo postman, onde você poderá testar e comparar retornos. Quote Link to comment Share on other sites More sharing options...
MAMP2 Posted August 7, 2020 Author Report Share Posted August 7, 2020 eu fiz gilmer, e no post o resultado é o esperado, quando faço via fivewin o resultado vem em branco este comando busca um token que eu devo pega-lo e colocar em um get e buscar os dados de um cliente, porem o token nao vem, ou seja, nao da erro na execução, mas nao vem nada a variavel cResp vem em branco. Quote Link to comment Share on other sites More sharing options...
MAMP2 Posted August 7, 2020 Author Report Share Posted August 7, 2020 Mandei o que eu fiz pra o pessoal dizer se tem alguma coisa errada que eu esteja fazendo, as vezes a gente olha e nao ve o obvio uma outra pessoa olha e percebe rapidamente, nao sei o que estou errando. Quote Link to comment Share on other sites More sharing options...
MAMP2 Posted August 9, 2020 Author Report Share Posted August 9, 2020 EDUTEK, como o seu ja funciona poderia me ajudar, nao estou conseguindo evoluir Quote Link to comment Share on other sites More sharing options...
MAMP2 Posted August 11, 2020 Author Report Share Posted August 11, 2020 EDUTEK, me ajude por favor Quote Link to comment Share on other sites More sharing options...
MAMP2 Posted August 11, 2020 Author Report Share Posted August 11, 2020 me mande seu contato, email, telefone pra gente conversar Quote Link to comment Share on other sites More sharing options...
kapiaba Posted August 11, 2020 Report Share Posted August 11, 2020 Veja se ajuda: http://forums.fivetechsupport.com/viewtopic.php?f=6&t=39256 Quote Link to comment Share on other sites More sharing options...
EDUTEK Posted August 11, 2020 Report Share Posted August 11, 2020 opa, (19) 98156-7871 Quote Link to comment Share on other sites More sharing options...
MAMP2 Posted August 11, 2020 Author Report Share Posted August 11, 2020 Kapiaba da erro na compilacao nao reconhece HB_JSONDcode, e xBrowse, sera que precisa de alguma LIB? Quote Link to comment Share on other sites More sharing options...
kapiaba Posted August 11, 2020 Report Share Posted August 11, 2020 Qual é a versão do seu fivewin? Talvez, tenhais que atualizar sua versão junto ao Gilmer. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.