dorneles Posted February 3, 2017 Report Share Posted February 3, 2017 alguem tem uma funcao para pegar os dados desse site? https://www.receitaws.com.br/v1/cnpj/1234567890123 Quote Link to comment Share on other sites More sharing options...
Edu Posted February 3, 2017 Report Share Posted February 3, 2017 Bom dia! Gostei da API! E é de graça! Tá na mão: ******************************************** Function GetDadosCNPJ() * retorna dados de um CNPJ * retorno no formato JSON * site que oferece o servico: https://www.receitaws.com.br Local oServerWS, cUrl, aArray, oCnpj:= SPACE(14) MsgGet("ReceitaWS", "Informe o CNPJ:", @oCnpj) cUrl:= "https://www.receitaws.com.br/v1/cnpj/"+Alltrim(oCnpj) Try oServerWS := CreateObject( 'MSXML2.ServerXMLHTTP.6.0' ) Catch e ? e:Description return nil End oServerWS:open('GET', cUrl, .f.) oServerWS:setRequestHeader('Content-Type' , 'text/xml; charset=utf-8') // Obtém ou define o valor de cabeçalho de Content-type HTTP. oServerWS:send() * Verifica o status do request. Exibe erro se houver IF oServerWS:Status != 200 // OK MsgStop( Alltrim(STR(oServerWS:Status)) +" - "+ oServerWS:StatusText , "Erro") RETURN NIL ENDIF WHILE oServerWS:readyState != 4 oServerWS:waitForResponse(1000) END * decodifica o arquivo json e transforma em um array multidimensional x := hb_jsondecode( oServerWS:responseText, @aArray ) if aArray == nil MsgStop("Erro ao retornar os dados. Tente novamente.") return nil endif if aArray['status'] != 'OK' // exibe erros MsgStop(aArray['message'], 'Erro') return nil endif xbrowse(aArray) // mostra o resultado return nil HERGON 1 Quote Link to comment Share on other sites More sharing options...
HERGON Posted February 3, 2017 Report Share Posted February 3, 2017 Boa tarde Interessante mais essa opção para pegarmos os dados informando o CNPJ, mas infelizmente não retorna a INSCRIÇÃO ESTADUAL. Herberson Gontijo aferra 1 Quote Link to comment Share on other sites More sharing options...
mkyx Posted February 13, 2017 Report Share Posted February 13, 2017 Onde encontro a função hb_jsondecode??? Quote Link to comment Share on other sites More sharing options...
Edu Posted February 14, 2017 Report Share Posted February 14, 2017 Onde encontro a função hb_jsondecode??? Esta função é nativa no xHarbour v 1.2.3 ou Harbour 3.2.x 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.