1
votes

In my application I passed a request api url and when I try to open the link it shows the Json data in the browser. But when I try to deserialize the Json data I got 404 status.

 Uri geocodeRequest = new Uri(string.Format("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=17.4271,078.4466&radius=500&type=petrol_bunk&key=MyKey"));

        HttpClient client = new HttpClient();

        HttpResponseMessage response = await client.GetAsync(geocodeRequest);
        if(response.IsSuccessStatusCode==true)
        {

When I open this link I can see the Json data but when I try this link in my code the status shows 404 error(No data resources). Also please check this link for the image displayed while debugging my project

1
Did you try to read using System.Net.Http.HttpResponseMessage tResponse = tClient.PostAsync(RequestUri, content).Result; string result = tResponse.Content.ReadAsStringAsync().Result;Nithin Paul
With out success response 200 how can we read the result..??ifaminsi

1 Answers

0
votes

It should be about the refuse from the server.
The different between using HttpClient & Web browser to browse website is

"You don't have the same header and method"

Let's try adding other header parameters like Agent,Content-type, Content-length

var client = new HttpClient();
var request = new HttpRequestMessage() {
                                        RequestUri = new Uri("http://www.someURI.com"),
                                        Method = HttpMethod.Get,
                                        ...........
                                    };

request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain")); }