dotnet-httpclient

HttpClient with infinite time out throws time out exception

僤鯓⒐⒋嵵緔 提交于 2019-12-09 12:30:37
问题 My HttpClient uses digest authentication to connect to the server and expects search queries in response. These search queries can come in any time so the client is expected to leave the connection open at all times. The connection is made using the following code: public static async void ListenForSearchQueries(int resourceId) { var url = $"xxx/yyy/{resourceId}/waitForSearchRequest?token=abc"; var httpHandler = new HttpClientHandler { PreAuthenticate = true }; using (var

.NET HTTPClient Asynchronous Limitations

房东的猫 提交于 2019-12-09 11:17:32
问题 I have a small .Net 4.5 C# app which reads information from a data source and then pushes this information to a web site which is a .NET 4.5 Web API site with a simple controller. The controller receives the data and puts it into a database. The following works for me, as fast as the application can read it can write and everything ends up in the DB: public static void PostDataToWebApi(MyDataClass tData) { HttpResponseMessage s = null; try { s = client.PostAsJsonAsync("/api/Station/Collector"

Connection was closed error between HttpClient and ASP.NET Core 2.0 webservice

我是研究僧i 提交于 2019-12-09 06:14:49
问题 I have a ASP.NET Core 2.0 webservice running on IIS. One of controller's methods looks more or less like this: [HttpGet()] public IActionResult Test() { // do some db updates and get data var result = DoSomeStuff(); // serialize data to byte array var output = Serialize(result); return File(output, "application/octet-stream"); } It does some database updates, query records from a table, serialize data and send them as a response. Data are sent in binary format. I'm using MessagePack-CSharp as

HttpResponseMessage.Content.Headers ContentDisposition is null

此生再无相见时 提交于 2019-12-09 02:14:07
问题 When downloading a file with HttpClient, I'm downloading first the headers and then the content. When headers are downloaded, I can see Headers collection on the Content property of HttpResponseMessage, but when accessing it through ContentDisposition on Headers, get null Why this is happening? Fiddler shows headers are fine... Code: var responseMessage = await httpClient.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(continueOnCapturedContext: false); Update 1 It

WebClient could not be found

我的梦境 提交于 2019-12-08 22:14:49
问题 I've already search on Stack Overflow (and google), but can't find the specific answer that solves my problem. I want to read some content out of a page. I've tried to use Webclient , but that gives me this error: The type or namespace name 'WebClient' could not be found (ae you missing a using directive or an assembly reference?) I've tried to search on google how to solve this error, but didn't find a correct answer (I've also tried HttpClient , same result). How do I make sure that I get

HttpClient doesn't report exception returned from web API

試著忘記壹切 提交于 2019-12-08 21:23:41
问题 I'm using HttpClient to call my MVC 4 web api. In my Web API call, it returns a domain object. If anything goes wrong, a HttpResponseException will be thrown at the server, with a customized message. [System.Web.Http.HttpGet] public Person Person(string loginName) { Person person = _profileRepository.GetPersonByEmail(loginName); if (person == null) throw new HttpResponseException( Request.CreateResponse(HttpStatusCode.NotFound, "Person not found by this id: " + id.ToString())); return person;

Putting a custom string in “Authorization” header in System.Net.HttpClient

僤鯓⒐⒋嵵緔 提交于 2019-12-08 20:16:16
问题 I am trying to use the System.Net.HttpClient class to post a message to Google Cloud Messaging. Google Cloud Message requires you to include a header called "Authorization", in a format similar to this: key=AIzaSyBxFuZ9IbtGbJHX6F5wdTc1mHnB7i0Lu8D But the HttpClient class throws an exception when I try this. string keyString = "key=AIzaSyBxFuZ9IbtGbJHX6F5wdTc1mHnB7i0LJ0w"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Add("Foo", keyString); // <== Proving I can client

Getting Bad Request error while updating email category with Office 365 API and HttpClient in C#

混江龙づ霸主 提交于 2019-12-08 19:05:33
I'm trying to to update email category and also mark it as read after that with the help of Outlook 365 API and HttpClient . Following this tutorial . In the tutorial the code is as below to update category and mark as read but, I'm not getting that how should I attach these details to HttpClient and request. PATCH https://outlook.office.com/api/v2.0/me/messages/AAMkAGE0Mz8S-AAA= Content-Type: application/json { "Categories": [ "Orange category", "Green category" ], "IsRead": true } The method and HttpClient I'm using are as below: Update 1 public string UpdateCategory(AuthenticationResult

Why do I get a 404 trying to post a large file to a Core Web API

廉价感情. 提交于 2019-12-08 15:14:59
问题 I am very new to file transfer between HttpClient and a Web API, so please excuse any ignorance and guesswork in my code. I have been trying to post a file created with System.IO.Compression.ZipFile to my web API now for about a day, and always I get a 404 response. If I post with an empty stream, the API action method is invoked, so I know the 404 is due to content and not the URI. This method is in the client WPF application that attempts to post the file: public async Task PostDirAsync

How-to workaround differences with Uri and encoded URLs in .Net4.0 vs .Net4.5 using HttpClient

十年热恋 提交于 2019-12-08 15:02:49
问题 Uri behaves differently in .Net4.0 vs .Net4.5 var u = new Uri("http://localhost:5984/mycouchtests_pri/test%2F1"); Console.WriteLine(u.OriginalString); Console.WriteLine(u.AbsoluteUri); Outcome NET4.0 http://localhost:5984/mycouchtests_pri/test%2F1 http://localhost:5984/mycouchtests_pri/test/1 Outcome NET4.5 http://localhost:5984/mycouchtests_pri/test%2F1 http://localhost:5984/mycouchtests_pri/test%2F1 So when using the HttpClient distributed by Microsoft via NuGet requests like the above fail