コード例 #1
0
        private void cmdSearch_Click(object sender, EventArgs e)
        {
            EntitySupport entity = GetNIF.GetFromNIFPT(txtnif.Text);

            if (entity != null && entity.result != "error")
            {
                Location loc = entity.records[Convert.ToInt32(txtnif.Text)];

                txtAdress.Text      = loc.address;
                txtdescription.Text = loc.title;
                txtCity.Text        = loc.city;
                txtZipCode.Text     = loc.pc4 + "-" + loc.pc3;
                txtPhone.Text       = loc.contacts.phone;
            }
            else
            {
                MessageBox.Show("No match found for the given NIF.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
コード例 #2
0
        public static EntitySupport GetFromNIFPT(string nif)
        {
            string baseUrl = "http://www.nif.pt/?json=1&q={0}&key={1}";

            {
                baseUrl = String.Format(baseUrl, nif, ApiKey);

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(baseUrl);

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    using (Stream stream = response.GetResponseStream())

                        using (StreamReader reader = new StreamReader(stream))
                        {
                            string        jsonString   = reader.ReadToEnd();
                            EntitySupport responseData = JsonConvert.DeserializeObject <EntitySupport>(jsonString);

                            return(responseData);
                        }
            }
        }