public static String restRecord(RequestRecord rec, String customerID) { //Format REST request String temp = $"https://address.melissadata.net/V3/WEB/GlobalAddress/doGlobalAddress?&id={customerID}&org={rec.Organization}&a1={rec.AddressLine1}&a2={rec.AddressLine2}" + $"&a3={rec.AddressLine3}&a4={rec.AddressLine4}&a5={rec.AddressLine5}&a6={rec.AddressLine6}" + $"&a7={rec.AddressLine7}&a8={rec.AddressLine8}&ddeploc={rec.DoubleDependentLocality}" + $"&deploc={rec.DependentLocality}&loc={rec.Locality}&subadmarea={rec.SubAdministrativeArea}" + $"&admarea={rec.AdministrativeArea}&subnatarea={rec.SubNationalArea}&postal={rec.PostalCode}" + $"&ctry={rec.CountryName}&format=JSON"; return(temp); }
public static void MakeRESTRequest(Record[] records) { //Create Request HttpWebRequest request = null; RequestRecord[] reqrec = new RequestRecord[records.Length]; for (int i = 0; i < records.Length; i++) { reqrec[i] = records[i].ToRequestRecord(); } foreach (RequestRecord rec in reqrec) { request = (HttpWebRequest)WebRequest.Create(restRecord(rec, "")); try { //Get Response WebResponse response = request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string jsonResponse = reader.ReadToEnd(); //Converts JSON to Usable object Result and outputs results try { Result.Rootobject result = JsonConvert.DeserializeObject <Result.Rootobject>(jsonResponse); foreach (Result.Record root in result.Records) { Console.WriteLine(root); } reader.Close(); } catch (Exception e) { Console.WriteLine(e.Message); } } catch (WebException ex) { //Output Error Console.WriteLine(ex.Message); } } }