0
I’m beginning to understand about API but I’m having a great difficulty because I’m trying to consume a JSON from an API according to the code below:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + api);
request.ContentType = "application/json";
request.Method = "GET";
request.Timeout = 30000;
request.ReadWriteTimeout = 30000;
var httpResponse = (HttpWebResponse)request.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var jsonReturn = streamReader.ReadToEnd();
dynamic dobj = JsonConvert.DeserializeObject<dynamic>(jsonReturn);
}
But this way it is giving error (Newtonsoft.Json.Jsonreaderexception: 'Unexpected Character encountered while Parsing value: <. Path '', line 0, position 0.')
Debugging the code I noticed that the var jsonReturn
is in bringing a file HTML
and in the dynamic dobj
is giving the error quoted above.
Thank you Cristiano, helped me a lot your answer.
– Caio Cesar