dotnet-httpclient

HttpClient does not return Content-Type

冷暖自知 提交于 2019-12-19 10:19:26
问题 I'm sending a request with HttpClient . Server returns two headers which I want return to client. I run it like this: using (var client = new HttpClient()) { var response = await client.GetAsync(DownloadUri + $"?path={path}&fileName={fileName}"); // ... } But on client side I have 10 headers, while server sends 12. This is what I get in debugger for response.Headers.ToString() : Transfer-Encoding: chunked X-SourceFiles: =?UTF-8?B

Curl -F equivalent in C#

江枫思渺然 提交于 2019-12-19 08:13:46
问题 I am trying to use HTTPClient object in C# to send a post request to an API. This is the CURL command: curl -X POST https://zzz.zzz.zzz/yyy -F Key=abcd -F media=@"audio.aac" I wrote the following code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Net.Http; using System.IO; using System.Net.Http.Headers; namespace Speech2Text { class Program { static void Main(string[] args) { curl().Wait(); } static async Task

Curl -F equivalent in C#

陌路散爱 提交于 2019-12-19 08:13:03
问题 I am trying to use HTTPClient object in C# to send a post request to an API. This is the CURL command: curl -X POST https://zzz.zzz.zzz/yyy -F Key=abcd -F media=@"audio.aac" I wrote the following code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Net.Http; using System.IO; using System.Net.Http.Headers; namespace Speech2Text { class Program { static void Main(string[] args) { curl().Wait(); } static async Task

Why do HttpClient.PostAsync and PutAsync dispose the content?

。_饼干妹妹 提交于 2019-12-19 03:21:53
问题 The behavior of the HttpClient.PostAsync method is to dispose of the provided HttpContent object. There are many ways to get around this behavior including constructing a new HttpContent for each call made on the client or loading the content to a stream and changing the pointer. I'm wondering why invoking this method automatically invokes the disposal of its IDisposable parameters? As far as I'm aware this is not a common behavior in .NET It's also worth noting that this behavior is observed

HttpClient buffer size limit exceeded

主宰稳场 提交于 2019-12-18 19:06:08
问题 I am using my client to get some info about a certain file stored in my Swift Object Storage which can be accessed throught REST Api. In Swift the HEAD method and url leading to specified object returns it's metadata (hash, timestamp, etc) contained in HTML response's (has NO CONTENT) headers. My code works perfectly when file size is < 2GB. I get HttpResponseMessage and I am able to parse it for required data, but when I ask for file > 2GB I get exception : "Cannot write more bytes to the

Why doesn't calling Task<T>.Result deadlock?

旧街凉风 提交于 2019-12-18 16:39:30
问题 After reading this post a few months ago, I became paranoid of getting the Result of a Task<T> and incessantly wrapped all of my calls to it with a ConfigureAwait(false) or Task.Run . However, for some reason the following code completes successfully: public static void Main(string[] args) { var arrays = DownloadMany(); foreach (var array in arrays); } IEnumerable<byte[]> DownloadMany() { string[] links = { "http://google.com", "http://microsoft.com", "http://apple.com" }; using (var client =

How can I convert this .NET RestSharp code to Microsoft.Net.Http HttpClient code?

瘦欲@ 提交于 2019-12-18 12:32:30
问题 I'm trying to figure out how to use HttpClient to POST some simple parameters. Email Password I've been doing this with RestSharp, but I'm trying to migrate off that. How can I do this with HttpClient , please? I have the following RestSharp code var restRequest = new RestRequest("account/authenticate", Method.POST); restRequest.AddParameter("Email", email); restRequest.AddParameter("Password", password); How can I convert that to use the (Microsoft.Net.Http) HttpClient class, instead? Take

HTTP Traffic monitoring issue when using MonoTouch, HttpClient and Charles Proxy

落花浮王杯 提交于 2019-12-18 04:52:57
问题 I'm new to HttpClient class and I'm having issue with monitoring requests using Charles Proxy. Basically what I need is to monitor the requests which are made either from simulator or actual iOS device. Here you can find a great tutorial of how to configure Charles for iOS development. I was making simple HttpClient requests for instance, just a simple authorisation async Task<string> authorizeUser() { HttpClient _client = new HttpClient (); _client.BaseAddress = new Uri("https://...../api/")

Connection keep-alive not working with System.Net.Http.HttpClient on certain hosts

ε祈祈猫儿з 提交于 2019-12-18 04:52:55
问题 I'm experimenting with the Heroku API using the .NET System.Net.Http.HttpClient . In particular, I want keep-alive to work so that I can send many HTTP requests using one TCP connection and only do one SSL handshake instead of setting up a TCP connection with SSL handshakes per request. I'm testing against https://api.heroku.com/status which gives a nice HTTP 200, and using Wireshark to monitor TCP traffic. Google Chrome, ApacheBench (with -k flag) and curl all seem to be able to keep a TCP

.net HttpClient with custom JsonConverter

[亡魂溺海] 提交于 2019-12-18 03:56:30
问题 I'm using .NET's HttpClient to make requests to a WebAPI that returns some JSON data that requires a little bit of custom deserialization on the client's side. For this I've made my own JsonConverter , but I can't figure out how to have the ReadAsAsync<T> method pick up the existence of the converter. I've solved my problem for now by using ReadAsStringAsync to read the response, then passing that string in to JsonConvert.DeserializeObject , but it seems like there should be a more elegant