/// Contém os dados do INPC para calculos financeiros
Class User.TabelaINPC Extends (%Persistent, %JSON.Adaptor)
{ Property Mes As %Integer [ Required ]; Index MesIndex On Mes [ Unique ]; Property Descricao As %String [ Required ]; Property Valor As %Double [ Required ]; ClassMethod leINPC() As %Status
{
Set result = ##class(%Net.HttpRequest).%New()
Set result.Server = "api.sidra.ibge.gov.br"
set result.SSLConfiguration = "padrao"
set result.Https = 0 --- HTTPS MUST Be ZERO, although there is a redirect to https in the browser
set result.SSLCheckServerIdentity = 0
set result.FollowRedirect = $$$YES
set result.ContentType = "application/json"
TRY {
set status = result.Get("/values/t/1736/n1/all/v/all/p/all/d/v44%202,v68%202,v2289%2013,v2290%202,v2291%202,v2292%202?formato=json")
set response = result.HttpResponse.Data
write "HTTP_CODE:"_result.HttpResponse.StatusCode,!
set dados = {}.%FromJSON(response)
set formatter = ##class(%JSON.Formatter).%New()
do formatter.Format(dados)
set iterator = dados.%GetIterator()
while iterator.%GetNext(.key, .value) { write "element:"_key_"=/"_value_"/ ",!} }
CATCH erro {
write "ERRO:",!
write erro.Name_", "_erro.Location_", error code "_erro.Code,!
do $system.OBJ.DisplayError()
RETURN erro.AsStatus()
}
Quit $$$OK
}
No, it din´t fix it. It didn´t find the server apisidra.ibge.gov.br. The correct one is api.sidra.ibge.gov.br. Does it make any difference if the connection is sync or async?
Yesterday the service was unstable, but today is working fine When I type de url in the browser I get the data, but in my code (I did as you told me to) HttpResponse.StatusCode returns 404.
go to post
Thank you !
go to post
Because the correct address is : http://api.sidra.ibge.gov.br/values/t/1736/n1/all/v/all/p/all/d/v44%202,...
That C# code is not working anymore. They presented it just as a sample.
Anyway, as I posted here, the problem is solved. Thank you for your attention !
go to post
Problem solved !
Thank you for the help Timothy !
go to post
Hi,
No, it din´t fix it. It didn´t find the server apisidra.ibge.gov.br. The correct one is api.sidra.ibge.gov.br.
Does it make any difference if the connection is sync or async?
Do I have to change the code because of it?
Thanks !
go to post
Just to add more information.
This is a C# Code that works fine :
HttpClient client = new HttpClient();
string baseApiAddress = "http://www.sidra.ibge.gov.br";
client.BaseAddress = new Uri(baseApiAddress);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.GetAsync("/api/values/t/1612/n2/all/v/all/p/last/c81/2702/f/u").Result;
It is a asynchronous connection.
go to post
I think I am doing something wrong before
set response = result.HttpResponse.Data
set dados = {}.%FromJSON(response)
I am getting error 404 although the access by the browser is ok.
Thanks !
go to post
Hi Timothy !
Thank´s for the help.
Yesterday the service was unstable, but today is working fine When I type de url in the browser I get the data, but in my code (I did as you told me to) HttpResponse.StatusCode returns 404.
I don´t know why...