Which exceptions can HttpClient throw?

As others have commented it depend on what you are calling with HttpClient. I get what you meant though and so here are some exceptions thrown with typical method calls. SendAsync can throw: ArgumentNullException The request was null. InvalidOperationException The request message was already sent by the HttpClient instance. HttpRequestException The request failed due to … Read more

HttpClient request throws IOException

It seems that this is caused by a recent security update for the .NET Framework: MS12-074: Vulnerabilities in .NET Framework could allow remote code execution: November 13, 2012 (KB 2745030) It all boils down to the following code in the web proxy resolution: [RegistryPermission(SecurityAction.Assert, Read=@”HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework”)] private static void InitializeFallbackSettings() { allowFallback = false; try { … Read more

C# unsupported grant type when calling web api

The default implementation of OAuthAuthorizationServerHandler only accepts form encoding (i.e. application/x-www-form-urlencoded) and not JSON encoding (application/JSON). Your request’s ContentType should be application/x-www-form-urlencoded and pass the data in the body as: grant_type=password&username=Alice&password=password123 i.e. not in JSON format. The chrome example above works because it is not passing data as JSON. You only need this for getting … Read more

Download file with WebClient or HttpClient?

You can do it natively with .Net 4.5+. I tried doing it your way and then I just found a method in Intellisense that seemed to make sense. https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.copytoasync?view=netframework-4.7.2 uri = new Uri(generatePdfsRetrieveUrl + pdfGuid + “.pdf”); HttpClient client = new HttpClient(); var response = await client.GetAsync(uri); using (var fs = new FileStream( HostingEnvironment.MapPath(string.Format(“~/Downloads/{0}.pdf”, pdfGuid)), … Read more

No MediaTypeFormatter is available to read an object of type ‘String’ from content with media type ‘text/plain’

Try using ReadAsStringAsync() instead. var foo = resp.Content.ReadAsStringAsync().Result; The reason why it ReadAsAsync<string>() doesn’t work is because ReadAsAsync<> will try to use one of the default MediaTypeFormatter (i.e. JsonMediaTypeFormatter, XmlMediaTypeFormatter, …) to read the content with content-type of text/plain. However, none of the default formatter can read the text/plain (they can only read application/json, application/xml, … Read more

The SSL connection could not be established

Yes, you can Bypass the certificate using below code… HttpClientHandler clientHandler = new HttpClientHandler(); clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; }; // Pass the handler to httpclient(from you are calling api) HttpClient client = new HttpClient(clientHandler);

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)