I've been trying to get a JSON response from a server through php. I can confirm that the uri correctly returns the JSON string I'm looking for so it's not an issue on that end. Also, this is only an issue with async request and a regular HTTP request call returns the correct JSON string.
Here is my async method:
public async Task<List> getUserInfoAsync(string username)
{
var client = new System.Net.Http.HttpClient();
client.BaseAddress = new Uri(address); // address is of form "http://www.something.com/"
var response = await client.GetAsync(phpScript + username); // phpScript is of form "php?username=" with 'username' being the requested username to grab from the database
var userJson = response.Content.ReadAsStringAsync().Result;
var rootObject = JsonConvert.DeserializeObject<userRoot>(userJson);
return rootObject.user;
}
So the 'response' variable ends up null which in turn causes userJson and rootObject.users to be null as well. I can't seem to figure out what is going wrong with the code. Any tips? Thanks!