Jump to content

Recommended Posts

Posted

Boa tarde a toda a comunidade.

Estou a tentar implementar no meu projecto em Winforms C#, a consulta à plataforma nif.pt utilizado o webservice disponibilizado por eles.

Já tentei vários procedimentos para "ler" o retorno, mas ainda não consegui nenhum resultado.

Alguém já fez este procedimento, que me possa dar umas dicas?

Obrigado desde já,

Cumprimentos,

Tiago Marques

Posted
            // API-KEY cfeb4a166 ....... c7d8a3a3940aac
            string nif = txtNIF.Text.Trim();
            
            string link = "http://www.nif.pt/?json=1&q=" + nif + "&key=cfeb4a166 ....... c7d8a3a3940aac";
            try
            {
                using (var client = new WebClient())
                {
                    var json = client.DownloadString(link);
                    JObject jsonObj = JObject.Parse(json);
                    JObject nifObj = (JObject)jsonObj["records"][nif];
                    // teste ok
                    MessageBox.Show(nifObj["address"].ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

Este é um exemplo básico e sem preocupações com boas práticas.

Espero que ajude.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.