static async Task RunAsyncHeroku() { //http://webtest1wlocate.azurewebsites.net/ using (var client = new HttpClient()) { HttpResponseMessage response; client.BaseAddress = new Uri("http://webtest1wlocate.azurewebsites.net/"); //client.BaseAddress = new Uri("http://113.11.254.198/_Testing/Heroku/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); string apiHeroku = "api/Heroku"; //HttpResponseMessage getResponse = await client.GetAsync(apiHeroku); //if (getResponse.IsSuccessStatusCode) //{ // Console.WriteLine(getResponse.Content.ReadAsStringAsync().Result); // Console.ReadLine(); //} RequestObj newRequest = new RequestObj(); CreatePayload(newRequest); //HttpResponseMessage reply = await client.PostAsJsonAsync(apiHeroku, newRequest); //HttpResponseMessage reply = await client.PostAsJsonAsync("", new ResponseObj()); HttpResponseMessage reply = await client.PostAsJsonAsync("", newRequest); if (reply.IsSuccessStatusCode) { ResponseObj arrResponse = await reply.Content.ReadAsAsync<ResponseObj>(); if (arrResponse.response != null && arrResponse.response.Count > 0) { foreach(Response currResponse in arrResponse.response) { Console.WriteLine("{0}\n{1}\n{2}\n\n", currResponse.image, currResponse.slug, currResponse.title); } } Console.WriteLine(reply.Content.ReadAsStringAsync().Result); } else { ResponseError arrResponse = await reply.Content.ReadAsAsync<ResponseError>(); Console.WriteLine(arrResponse.error); } Console.ReadLine(); } }
private static void CreatePayload(RequestObj newRequest) { newRequest.payload = new List<Payload>(); //1st item Payload pload1 = new Payload(); pload1.country = "UK"; pload1.description = "What's life like when you have enough children to field your own football team?"; pload1.drm = true; pload1.episodeCount = 3; pload1.genre = "Reality"; pload1.image = new Image(); pload1.image.showImage = "http://catchup.ninemsn.com.au/img/jump-in/shows/16KidsandCounting1280.jpg"; pload1.language = "English"; pload1.nextEpisode = null; pload1.primaryColour = "#ff7800"; pload1.seasons = new List<Season>(); pload1.seasons.Add(new Season() { slug = "show/16kidsandcounting/season/1" }); pload1.slug = "show/16kidsandcounting"; pload1.title = "16 Kids and Counting"; pload1.tvChannel = "GEM"; newRequest.payload.Add(pload1); //2nd item pload1 = new Payload(); pload1.slug = "show/seapatrol"; pload1.title = "Sea Patrol"; pload1.tvChannel = "Channel 9"; newRequest.payload.Add(pload1); //3rd item pload1 = new Payload(); pload1.country = "USA"; pload1.description = "The Taste puts 16 culinary competitors in the kitchen, where four of the World's most notable culinary masters of the food world judges their creations based on a blind taste. Join judges Anthony Bourdain, Nigella Lawson, Ludovic Lefebvre and Brian Malarkey in this pressure-packed contest where a single spoonful can catapult a contender to the top or send them packing."; pload1.drm = true; pload1.episodeCount = 2; pload1.genre = "Reality"; pload1.image = new Image(); pload1.image.showImage = "http://catchup.ninemsn.com.au/img/jump-in/shows/TheTaste1280.jpg"; pload1.language = "English"; pload1.nextEpisode = new NextEpisode() { channel = null, channelLogo = "http://catchup.ninemsn.com.au/img/player/logo_go.gif", date = null, html = "<br><span class=\"visit\">Visit the Official Website</span></span>", url = "http://go.ninemsn.com.au/" }; pload1.primaryColour = "#df0000"; pload1.seasons = new List<Season>(); pload1.seasons.Add(new Season() { slug = "show/thetaste/season/1" }); pload1.slug = "show/thetaste"; pload1.title = "The Taste"; pload1.tvChannel = "GEM"; newRequest.payload.Add(pload1); newRequest.skip = 0; newRequest.take = 10; newRequest.totalRecords = 75; }