HttpClient in using statement

The difference is that in the top loop, you’re creating 10 total HttpClient objects, using each once, and then disposing of each, while in the bottom, you’re creating just one HttpClient and reusing it. The point of the article is that it’s quite inefficient – and wholly unnecessary – to make a new HttpClient object … Read more

Examples of Repository Pattern with consuming an external REST web service via HttpClient?

A simple example: // You need interface to keep your repository usage abstracted // from concrete implementation as this is the whole point of // repository pattern. public interface IUserRepository { Task<User> GetUserAsync(int userId); } public class UserRepository : IUserRepository { private static string baseUrl = “https://example.com/api/” public async Task<User> GetUserAsync(int userId) { var userJson … Read more

HttpClient & SOAP (C#)

I needed to do this myself and since I couldn’t find any answers online, here’s what I worked out. This uses a simple SOAP calculator service with an ‘Add’ method that takes two numbers and returns the sum. public async Task<int> AddNumbersAsync(Uri uri, int a, int b) { var soapString = this.ConstructSoapRequest(a, b); using (var … Read more

How do I add query parameters to a GetMethod (using Java commons-httpclient)?

Post methods have post parameters, but get methods do not. Query parameters are embedded in the URL. The current version of HttpClient accepts a string in the constructor. If you wanted to add the key, value pair above, you could use: String url = “http://www.example.com/page?key=value”; GetMethod method = new GetMethod(url); A good starting tutorial can … Read more

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