dotnet-httpclient

How do I not exclude charset in Content-Type when using HttpClient?

只愿长相守 提交于 2019-12-23 17:17:13
问题 I am attempting to use HttpClient in a .net core project to make a GET request to a REST service that accepts/returns JSON. I don't control the external service. No matter how I try, I can't figure out to set the Content-Type header to application/json only . When I use client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); it sends in the HTTP GET request: Content-Type: application/json; charset=utf-8 However, this particular service does not work

Using HttpWebRequest, Keep-alive not working for many similar requests to localhost

醉酒当歌 提交于 2019-12-23 05:34:15
问题 I'm using HttpWebRequest to send many sync requests to the same HTTP URL on localhost, and I need to re-use TCP connections to prevent ephemeral port depletion. But I don't seem to be able to get Keep-alive working. Here's my code where I make the HTTP request: var request = (HttpWebRequest) WebRequest.Create(url); HttpWebResponse response = null; request.Method = "GET"; request.KeepAlive = true; try { response = (HttpWebResponse) request.GetResponse(); // ... } catch (Exception e) { // ... }

How to return result from Task<HttpResponseMessage>, to take the benefit of Async HttpClient call?

萝らか妹 提交于 2019-12-23 05:33:07
问题 Can I write code (1st) like bellow public Task<HttpResponseMessage> Get(int id) { return Task<HttpResponseMessage>.Factory.StartNew(() => Request.CreateResponse(HttpStatusCode.OK, JsonConvert.SerializeObject(model))); } Can I write code (2nd) like bellow public Task<HttpResponseMessage> Put(int id, string value) { return Task<HttpResponseMessage>.Factory.StartNew(() => Request.CreateResponse(HttpStatusCode.OK)); } I want call above described Put method using Httpclient.PutAsJsonAsync() . in

How to upload an XML file using multipart/form-data with Restsharp?

拜拜、爱过 提交于 2019-12-23 04:13:11
问题 Question: How to upload an XML file using multipart/form-data with Restsharp? Problem: I'm using Peppol for sending invoices using the Codabox API. I want to upload an xml to the rest service. The rest service itself is under control by the provider Codabox. I have 2 methods provided who I expect to do the same. First of all with Postman and httpclient, all the things works fine. I want to get the same from the httpclient method working using the restsharp way. RestSharp version: 106.2.1

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

独自空忆成欢 提交于 2019-12-23 02:50:15
问题 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

Is it possible to use Furl.Http with the OWIN TestServer?

此生再无相见时 提交于 2019-12-23 02:31:22
问题 I'm using the OWIN TestServer which provides me an HttpClient to do my in memory calls to the test server. I'm wondering if there's a way of passing in the existing HttpClient for Flurl to use. 回答1: UPDATE: Much of the information below is no longer relevant in Flurl.Http 2.x. Specifically, most of Flurl's functionality is contained in the new FlurlClient object (which wraps HttpClient ) and not in a custom message handler, so you're not losing functionality if you provide a different

async await execution windows phone 8

半城伤御伤魂 提交于 2019-12-23 02:28:35
问题 I am new to async and await style of programming. How can I solve the following problem: I am calling the below code first. The problem here is that the first line is awaiting which need to populate the categoriesvm.Categorieslist , which it does not, but the second line is called. (which I think is the default behaviour of await) How can I make sure that the second line is called only when the categoriesvm.Categorieslist is populated in the first line? protected override void OnNavigatedTo

Control total number of tasks when using Async/Await in a recursive function

一个人想着一个人 提交于 2019-12-23 01:41:18
问题 I have written this code. It recursively creates folders in the web system by making REST Calls. So basically, it creates a folder for the root node, then gets all the child nodes and parallely and recursively calls itself. (for each child) the only problem with the code is that if a node has too may children OR if the hierarchy is too deep, then I start getting "TaskCancellation" errors. I have already tried increasing the timeout to 10 minutes.. but that does not solve the problem. So my

Delphi: TIdHTTP vs TNetHTTPClient

走远了吗. 提交于 2019-12-22 17:59:23
问题 I'm writing a download manager in Delphi with some custom features like resumable downloads and downloading through proxies. I'm studing different component solutions: Indy and NetHTTP, both seem very close. TNetHTTPClient seem to be an interface of winhttp.dll . TIdHTTP seem to be an interface of wininet.dll (but i'm not sure). TIdHTTP seems like a very old component (maybe very stable/tested) and has tons of documentation online. TNetHTTPClient seems to be a very recent component, and doesn

Deadlock reading async response content from async DelegatingHandler in webapi

百般思念 提交于 2019-12-22 13:59:11
问题 Problem I'm using a DelegatingHandler in WebAPI to read the response Content and audit it to the database. When the code gets to .ReadAsStringAsync() it appears to lock and prevent other requests from completing. I only know this, because when I remove the offending line, it works perfectly. public static void Register(HttpConfiguration config) { config.MessageHandlers.Add(new ResourceAuditHandler()); } public class ResourceAuditHandler : DelegatingHandler { protected override async Task