dotnet-httpclient

Retrying HttpClient Unsuccessful Requests

╄→尐↘猪︶ㄣ 提交于 2019-12-27 11:37:07
问题 I am building a function that given an HttpContent Object, will issues request and retry on failure. However I get exceptions saying that HttpContent Object is disposed after issuing the request. Is there anyway to copy or duplicate the HttpContent Object so that I can issue multiple requests. public HttpResponseMessage ExecuteWithRetry(string url, HttpContent content) { HttpResponseMessage result = null; bool success = false; do { using (var client = new HttpClient()) { result = client

HttpResponseMessage.Content.Header ignoring charset setting in meta tag in html source

时光毁灭记忆、已成空白 提交于 2019-12-25 08:48:33
问题 I have just posted this question, which answer came right away. It, in turn, creates the following new question: If my understanding is correct, the StreamContent object, from HttpResponseMessage , is created upon making an HTTP request via HttpClient.GetAsync . Its Header property, or part of it, will be set according to meta tags included in the HTML source file. For instance, a meta tag can tell the response object with which charset encode the file's contents. <meta http-equiv='Content

How do I replace curl invoke with HttpClient object invoke or some similar?

你。 提交于 2019-12-24 23:18:39
问题 There is a code that creates new featureType at geoserver: string par = @"/c D:\curl-7.32.0-ssl-sspi-zlib-static-bin-w32\curl.exe -v -u admin:MYPASSWORD -XPOST -H ""Content-type: text/xml"" -d ""<featureType><name>" + name + @"</name><title>" + MyHtmlEncode(title) + @"</title></featureType>"" http://localhost:8080/geoserver/rest/workspaces/cite/datastores/postgis/featuretypes"; Process P = Process.Start(@"C:\Windows\System32\cmd.exe",par); I want to read output of server and handle errors,

Why is System.Net.Http HttpClient encoding my request URL?

强颜欢笑 提交于 2019-12-24 20:43:23
问题 I use the HttpClient in System.Net.Http to make requests to a web service as below: using (var client = new HttpClient()) { using (var response = client.GetAsync(url).Result) { var result = response.Content.ReadAsStringAsync().Result; } } I have a sandbox application and a live application. The sandbox application has identical code (in a shared repository) which works fine, but when client.GetAsync(url).Result is called in the live application, for some reason Fiddler shows me that the

why HttpClient.GetAsync causes opening link in browser?

此生再无相见时 提交于 2019-12-24 12:13:18
问题 Assume we have an application that wants access popular Russian social network VK and written on C# with WinForms GUI. VK uses OAuth2-similiar approach, so we need to open web browser with vk oauth authorization url. Then we subscribe to webBrowser's OnNavigated event and waiting until url will not be equal some pre-defined url with access token in query string. From now on we can call vk methods using received access token, but some strange things take place here: when i try to invoke some

ErrOR 0x80072efd when sending an Http request to rest api on Windows Phone 8.1 Emulator

ぐ巨炮叔叔 提交于 2019-12-24 11:26:26
问题 I'm currently working on a Windows Phone 8.1 app, my first one actually. I would like to send through my emulator windows phone 8.1, a http request to a remote server. So I've used that code: try { mailToCheck.MailProfil = TxtBox_mail.Text.ToString(); string js = JsonConvert.SerializeObject(mailToCheck); HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("Accept", "Application/JSON"); HttpRequestMessage data = new HttpRequestMessage(HttpMethod.Post, new Uri("url");

Bug when using await/async for System.Net.Http with .NET Core (.NET Standard 1.4 and .NET Framework 4.6.1)?

房东的猫 提交于 2019-12-24 07:02:37
问题 Foreground: I was investigating a bug in an ASP.NET Core project (targeting .NET 4.6.1, using assemblies from .Net Standard 1.4), that threw a MissingMethodException, although this in no way could be possible. Isolating the faulting method, I took the core of the code out to a separate unit test which also targets .NET 4.6.1. The exception I receive, ThreadAbortException , from the unit test is more or less this (it sometime various): at System.Net.Http.WinHttpHandler

Bug when using await/async for System.Net.Http with .NET Core (.NET Standard 1.4 and .NET Framework 4.6.1)?

喜你入骨 提交于 2019-12-24 07:02:17
问题 Foreground: I was investigating a bug in an ASP.NET Core project (targeting .NET 4.6.1, using assemblies from .Net Standard 1.4), that threw a MissingMethodException, although this in no way could be possible. Isolating the faulting method, I took the core of the code out to a separate unit test which also targets .NET 4.6.1. The exception I receive, ThreadAbortException , from the unit test is more or less this (it sometime various): at System.Net.Http.WinHttpHandler

Unsupported Media Type with HttpClient / .NET Core

半世苍凉 提交于 2019-12-23 22:22:54
问题 I am working with a RESTful API that supports POST requests in JSON format. The API's own Swagger documentation shows that this is a valid call to one of its endpoints: curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '<JSON>' '<URL>' Where <JSON> and <URL> are the valid JSON message and the endpoint's URL. From this Swagger documentation I gather that any posts to this endpoint must include both a Content-Type and Accept headers set to application

System.Net.Http.HttpClient not Respect timeouts and use everytime the default Value

空扰寡人 提交于 2019-12-23 19:21:23
问题 I'm using HttpClient to interact with a webservice (written by my Company) with a lot of apis. All the apis work great except when one of that (the bigger and slower) take more than 100 seconds to give an answer, passed that time i receive the following error(N.B: If the api take less than 100s all works well): System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: The operation has timed out. at System.Net.HttpWebRequest+