I have code like this:
public async Task<string> getToken()
{
string uri = "http://localhost/api/getToken";
HttpClient client = new HttpClient();
//client.BaseAddress = new Uri(uri);
string token = "asfd";
string baseId = "asfasdf";
string appVersion = "afsadf";
string content = "";
HttpResponseMessage response = null;
try
{
string url = string.Format("{0}?token='{1}'&baseId='{2}'&appVersion='{3}'", uri, token, baseId, appVersion);
//client.BaseAddress = new Uri(url);
response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode();
content = await response.Content.ReadAsStringAsync();
}
catch (Exception ex)
{
}
return content;
}
And when I get to the line when is GetAsync called VS turn off debug mode and does not throw any exception. On the server I have breakpoint in the action in controller (mvc web api) and it is not reached. But when I copy url and past it to the browser action in controller is invoked. And when I change my url for some other incorrect url, GetAsync throw exception which is captured in catch. My application is in .net framework 4.5, console application. Maybe I must add any dll ?