dotnet-httpclient

HttpClient reused with client certificate

爱⌒轻易说出口 提交于 2019-12-08 03:47:34
问题 I've read at several places (like here, here or here) that it's a bad practice to dispose of the HttpClient directly after a request and it's better to dispose of it after all the request have been made, to allow reuse of the connection. To try that out, I've created an instance of HttpClient and added to a static field in my class this way: public class Test { private static X509Certificate2 _certificate; private static HttpClient HttpClient { get; set; } ... public Test() { ... if

Can't Install System.Net.Http Package into a Windows Phone 7.1 Silverlight Project

风格不统一 提交于 2019-12-07 23:57:49
问题 I used Nuget to install the "Microsoft ASP.NET Web API Client Libraries" to get the latest System.Net.Http assembly for use in Windows Phone 7.1 XNA and Silverlight projects. It installs just fine into my WP7.1 XNA projects, but doesn't allow me to install it into the WP7.1 Silverlight projects. I even tried installing it directly from the Package Manager Console into a newly created WP7.1 Silverlight project and got this Error response: PM> Install-Package System.Net.Http Attempting to

Webapi 2.0 how to implement refresh JWT token when access token expired

穿精又带淫゛_ 提交于 2019-12-07 20:32:09
问题 I am quite new in web API implementation, I have created a web API service to use it with ASP.net web form applications as well as some stand alone applications(C# Console/Windows application) using HttpClient object. I have implemented a basic JWT access token authentication with expiration time limit in web api, this authentication technique is working fine until token not expired, when token get expired web api does not accept request as token has expired! which is fine as per

HttpClient - Xamarin Android - MvvmCross

巧了我就是萌 提交于 2019-12-07 14:08:58
问题 I've been developing an application for Android using Xamarin with MvvmCross and everything has been going fine, me and my team were able to develop the solution and this week we decided to make the final adjustments and to test the application in other environments. During the tests I had a huge problem with the Android solution. In the working environment everything was working fine but when I tried to test the application at home the application stopped working. I checked what was

Deadlock while blocking async HttpClient call within a task continuation

若如初见. 提交于 2019-12-07 14:07:11
问题 I am trying to wrap my head around synchronously calling async functions and deadlock. In the below example I am blocking an async call which internally uses ConfigureAwait(false) which as far as I can tell should prevent deadlock. The first call to the web service does not deadlock. However, the second one that happens within a continuation that syncs back to the UI thread deadlocks. GetBlocking_Click is a click event in a WPF app so both the first and the second request happen on the UI

HttpRequestException when doing a client.SendAsync

Deadly 提交于 2019-12-07 13:54:49
问题 All of a sudden, this piece of code that usually works started throwing HttpRequestException errors. In the logs, I see that the request was actually sent 1 minute and 35 seconds before the error was thrown. Could it be a timeout issue? Here is the code: private async Task<HttpResponseMessage> RunRequest(HttpRequestMessage request) { var client = new HttpClient(); var response = await client.SendAsync(request).ConfigureAwait(false); return response; } Here is the caller (there could between

Certificate error when configuring HttpClientFactory

余生颓废 提交于 2019-12-07 08:21:48
问题 I need to add certificate in HttpClientFactory . Old implementation with HttpClient look this: var cookieContainer = new CookieContainer(); var handler = new HttpClientHandler { CookieContainer = cookieContainer }; var basePath = Directory.GetCurrentDirectory(); var certificatePath = Path.Combine(basePath, certPath); var fileExists = File.Exists(certificatePath); if (!fileExists) throw new ArgumentException(certificatePath); var certificate = new X509Certificate2(certificatePath, certPwd);

C# HttpClient not sending basic authentication after redirect

南楼画角 提交于 2019-12-07 08:10:25
问题 My code is making an HTTP GET to a web service URL that requires basic authentication. I've implemented this using an HttpClient with an HttpClientHandler that has the Credentials property defined. This all works perfectly.. Except for one of my use-cases where I'm making the authenticated GET to: http://somedomain.com which redirects to http://www.somedomain.com . It seems that the HttpClientHandler clears the authentication header during the redirect. How can I prevent this? I want the

How to upload an XML file using multipart/form-data with Restsharp?

拥有回忆 提交于 2019-12-07 07:52:28
Question: How to upload an XML file using multipart/form-data with Restsharp? Problem: I'm using Peppol for sending invoices using the Codabox API. I want to upload an xml to the rest service. The rest service itself is under control by the provider Codabox. I have 2 methods provided who I expect to do the same. First of all with Postman and httpclient, all the things works fine. I want to get the same from the httpclient method working using the restsharp way. RestSharp version: 106.2.1 Error message with Restsharp response = "StatusCode: BadRequest, Content-Type: application/json, Content

Bad request error while adding a lookup GUID field in CRM database using Web API

ⅰ亾dé卋堺 提交于 2019-12-07 07:10:01
问题 I want to insert a new record in CRM's custom entity where one of the fields is of lookup type i.e. new_contactid and it is dependent on the contact entity. I have also referred Set Values of all Data Types using Web API in Dynamics CRM Through C#. My JSON data is as below: { "new_transactionnumber":"114", "new_transactionamount":650, "new_transactiondate":"2018-01-29T15:01:00.000Z", "new_contactid_contact@odata.bind":"/contacts(afb9e006-6be5-e711-80ed-bef806786223)", "new_moveid_new_move