Upload image using HttpClient

Okay after hours of researching I came to the point that I should restart from draft. I simulate a Html form upload with following C# code: private async Task<string> UploadImage(StorageFile file) { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(“http://your.url.com/”); MultipartFormDataContent form = new MultipartFormDataContent(); HttpContent content = new StringContent(“fileToUpload”); form.Add(content, “fileToUpload”); var stream … Read more

ANDROID : Share session between Webview and httpclient

So , this is what I did and it worked for me – HttpRequestBase request = new HttpGet(uri); request.addHeader(“Cookie”, getCookieFromAppCookieManager(uri.toString())); Now the implmentation for the getCookieFromAppCookieManager is as follows – The method gets the cookies for a given URL from the application CookieManager. The application CookieManager manages the cookies used by an application’s WebView instances. … Read more

HttpClientHandler / HttpClient Memory Leak

Using the repro form Alexandr Nikitin, I was able to discover that this seems to happen ONLY when you have HttpClient be a short lived object. If you make the handler and client long lived this does not seem to happen: using System; using System.Net.Http; using System.Threading.Tasks; namespace HttpClientMemoryLeak { using System.Net; using System.Threading; class … Read more

C#: HttpClient, File upload progress when uploading multiple file as MultipartFormDataContent

I have a working version of ProgressableStreamContent. Please note, I am adding headers in the constructor, this is a bug in original ProgressStreamContent that it does not add headers !! internal class ProgressableStreamContent : HttpContent { /// <summary> /// Lets keep buffer of 20kb /// </summary> private const int defaultBufferSize = 5*4096; private HttpContent content; … Read more

GZip POST request with HTTPClient in Java

You need to turn that String into a gzipped byte[] or (temp) File first. Let’s assume that it’s not an extraordinary large String value so that a byte[] is safe enough for the available JVM memory: String foo = “value”; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (GZIPOutputStream gzos = new GZIPOutputStream(baos)) { gzos.write(foo.getBytes(“UTF-8”)); } byte[] … Read more

Maximum concurrent requests for WebClient, HttpWebRequest, and HttpClient

Yes, there is a limit. The default connection limit is 2 concurrent connections per remote host. This can be overridden. For example, I believe that ASP.NET by default overrides the default to be 10 connections per remote host. From https://msdn.microsoft.com/en-us/library/7af54za5.aspx: The number of connections between a client and server can have a dramatic impact on … Read more