Consider migrating from HttpWebRequest to HttpClient
When trying to debug the dot net library we are unable to view the communications between Adyen and the client server because HttpWebRequest does not have logging built in. Exceptions are also thrown in HttpWebRequest and have to be caught and parsed to get the status code in some situations. This last part is noisy (shows in logs even if handled), slow and error prone.
The new HttpClient approach;
- Can be logged easily via the appsettings, enabling traffic to be monitored for debugging.
- Handles connection pooling via the HttpClientFactory class, meaning better use of sockets which helps in a busy app.
- Can be swapped out for testing via the IHttpClient interface.
- Does not throw exceptions for standard status codes such as 404 instead returns the status with an IsSuccessStatusCode property.
- Is .Net Standard compatible and is the now standard approach.
- Can still be used from older .net versions.
I appreciate it is a framework level thing and not related to the product, it would help us a lot whilst developing and debugging.
Hello @RyanONeill1970,
It is a decision from our side to not add any logging into the libraries. On the other hand you are more than welcome to implement the suggestions which we could review them. You can follow the contributing guidelines
kind regards, Alexandros Adyen
@AlexandrosMor it's not only about the logging. The current solution has performance issues. Under the hood httpWebRequest.GetResponse() method creates HttpClient for each call.
Take a look at these articles for more information:
- https://josef.codes/you-are-probably-still-using-httpclient-wrong-and-it-is-destabilizing-your-software/
- https://makolyte.com/csharp-switch-from-using-httpwebrequest-to-httpclient/
- https://www.aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/
Hi @RyanONeill1970 and @kipwoker,
Thank you both for reaching out to us and contributing. We have finally arrived at this library with our automation process and will thus start very soon with some big changes. This includes the HttpClient, as it will need to be RESTful anyways. We will be sure to use your feedback during this process. If there is anything you guys would like to see, please do let us know.
Best, Jilling Adyen