This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Net.Http; | |
using System.Net; | |
namespace HTTP_Test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Startup | |
{ | |
public IServiceProvider ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMvc().AddJsonOptions(options => | |
{ | |
options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); | |
options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//2 Scenarios. Either returning a list of json objects you can deserailze to .net objects | |
// OR returning a single json object, but the first property of the object is a list, and inside the list is the value you actually want. | |
HttpResponseMessage response = await client.GetAsync(targeturl); | |
response = await client.GetAsync(finalRequestUri); | |
var content = response.Content; | |
// ... Read the string. | |
string json = await content.ReadAsStringAsync(); | |
JObject rss = JObject.Parse(json); | |
//1st scenario; i am returning an array of json objects, that will later be desearilzed. |