title: 'System.Net.Http.HttpRequestException' occurred in mscorlib.dll but was not handled in user code
body: <p>We are developing the windows forms application to authenticate a windows forms application to a Azure AD.</p>
  
  <p>I have a couple of issues and the resources online are all seems to be outdated.</p>
  
  <p>As suggested by the below link I have created a webapi and native client api  and windows forms application.</p>
  
  <p>In web api I have updated the manifest files as follows</p>
  
  <p>"oauth2Permissions": [</p>
  
  <pre><code>{
  
    "adminConsentDescription": "Allow the application to access ftpwebapi on behalf of the signed-in user.",
  
    "adminConsentDisplayName": "Access ftpwebapi",
  
    "id": "4eebeb18-aee6-408a-bea1-c090766dce23",
  
    "isEnabled": true,
  
    "origin": "Application",
  
    "type": "User",
  
    "userConsentDescription": "Allow the application to access ftpwebapi on your behalf.",
  
    "userConsentDisplayName": "Access ftpwebapi",
  
    "value": "user_impersonation"
  
  }
  </code></pre>
  
  <p>],</p>
  
  <p>And added under keys I have added an entry for 2 years and added the webapi to the native client application.</p>
  
  <p>In the windows forms I have added the below code in the button click event.</p>
  
  <p>private async void button1_Click(object sender, EventArgs e)</p>
  
  <pre><code>    {
  
          string authority = "https://login.windows.net/****";
  
          string resourceURI = "https://***.com/WebApplication3";
  
          string clientID = "********-5815-4358-****-*********";
  
          Uri returnURI = new Uri("http://********.com");
  
          AuthenticationContext authContext =
  
              new AuthenticationContext(authority);
  
          AuthenticationResult authResult =
  
              authContext.AcquireToken(resourceURI, clientID, returnURI);
  
          string authHeader = authResult.CreateAuthorizationHeader();
  
          // don't do this in prod
  
          System.Net.ServicePointManager.ServerCertificateValidationCallback =
  
              ((s, c, c2, se) =&gt; true);
  
          HttpClient client = new HttpClient();
  
          HttpRequestMessage request =
  
              new HttpRequestMessage(HttpMethod.Get, "https://localhost:***/task/api/");
  
          request.Headers.TryAddWithoutValidation("Authorization", authHeader);
  
          var response = await client.SendAsync(request);
  
          string responseString = await response.Content.ReadAsStringAsync();
  
          MessageBox.Show(responseString);
  </code></pre>
  
  <p>}</p>
  
  <p>Is it the right way so far ?</p>
  
  <p>And I am agetting an error in</p>
  
  <p>var response = await client.SendAsync(request);</p>
  
  <p>An exception of type 'System.Net.Http.HttpRequestException' occurred in mscorlib.dll but was not handled in user code</p>
  
  <p>Additional information: An error occurred while sending the request.</p>