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);
}
Debug.WriteLine(result);
}
LarsTech
81.8k14 gold badges161 silver badges235 bronze badges
1 Answer 1
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.
answered Sep 5, 2016 at 14:23
lang-cs
text/html; charset= utf-8
.you cannot expect json here.