예제 #1
0
        void AddressValidation_CorrectBody()
        {
            Console.WriteLine("===== {0} =====", "POST AddressValidation_CorrectBody");
            Console.WriteLine("");

            var post = new AddressToValidate
            {
                Consignee = "0123456789 0123456789 0123456789 0123456789",
                Address = new AddressToValidate.AddressObject
               {
                   StreetAddress = "1 Some Street",
                   City = "NSW",
                   Suburb ="Mascot",
                   PostCode = "2020",
                   CountryCode = "Au"
               }
            };
            PostValidationRequest(post);
        }
예제 #2
0
        private void PostValidationRequest(AddressToValidate post)
        {
            HttpResponseMessage response = client.PostAsJsonAsync("v2/addressvalidation", post).Result;  // Blocking call!
            if (response.IsSuccessStatusCode)
            {
                // Parse the response body. Blocking!
                var data = response.Content.ReadAsStringAsync().Result;

                if (!string.IsNullOrEmpty(data) && data != "null")
                {
                    var obj = JsonConvert.DeserializeObject<AddressValidationResponse>(data);

                    if (obj.Validated)
                        Console.WriteLine("State/Suburb/Postcode/Country: CORRECT");

                    foreach (var item in obj.Errors)
                    {
                        Console.WriteLine(item);
                    }
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
            Console.WriteLine("");
        }