AAP AAP - 6 months ago 39
C# Question

C# API return HTML instead JSON

Don't know why a web request return HTML instead JSON. Can anyone please help.

private void Test()
string url = "https://www.netonnet.no/Category/GetFilteredCategory";

string json = "{'sectionId':'10978','filter': '[]','sortOrder':-1,'sortBy':0,'pageSize':96,'listType':'10'}";

string result = "";
using (var client = new WebClient())
client.Headers[HttpRequestHeader.ContentType] = "application/json";
result = client.UploadString(url, "POST", json);


When your asking an you want it in a specific format you should add

client.Headers[HttpRequestHeader.Accept] = "application/json";

This will tell the API that you want it in json, but this only works if they can give it to you in that format.

And like Amit Kumar Ghosh said in a comment above, it seems like they don't serve json.