-1

I can read the json file if i put it on the project folder but I can't read it if i have it on a url path like http://111.111.111.111/test/test.json

try
{
  string filePath = @"http://111.111.111.111/test/test.json";

  //this way works
  // using (StreamReader r = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "test.json"))
  using ( StreamReader r = new StreamReader(filePath) )
  {
    string json = r.ReadToEnd();
    var items = JsonConvert.DeserializeObject<Item>(json);
  }
}
catch
{
}
anatp_123
  • 43
  • 6

1 Answers1

-1

Is this a duplicate of: Receiving JSON data back from HTTP request

HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync("http://www.contoso.com/");
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();

Does it need to be using StreamReader?

In any case, you need to make a HTTP request to retrieve the data.

Soc
  • 7,425
  • 4
  • 13
  • 30