public static void MakeBATCHJSONRequest(BatchRequest batch) { //Makes the request to the webservice try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"http://address.melissadata.net/v3/WEB/GlobalAddress/doGlobalAddress"); request.ContentType = $"text/json"; request.Method = "POST"; request.Accept = $"application/json"; try { using (StreamWriter write = new StreamWriter(request.GetRequestStream())) { write.Write(JsonConvert.SerializeObject(batch)); } try { //Gets response WebResponse response = request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string jsonResponse = reader.ReadToEnd(); reader.Close(); //Converts JSON to Usable object Result.RootObject and outputs results try { Result.Rootobject result = JsonConvert.DeserializeObject <Result.Rootobject>(jsonResponse); if (result.Records != null) { foreach (Result.Record root in result.Records) { Console.WriteLine(root); } } } catch (WebException ex) { Console.WriteLine(ex); } } catch (WebException ex) { Console.WriteLine(ex.Message); } } catch (WebException ex) { Console.WriteLine(ex.Message); } } catch (WebException ex) { Console.WriteLine(ex.Message); } }
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); } } }