dotnet-httpclient

Received an unexpected EOF or 0 bytes from the transport stream. (Previous Answers to the Same Question Doesn't Apply)

假如想象 提交于 2021-02-20 03:48:54
问题 I get this InnerException with below Exception Tree; My Code is; public T GetQueryResultsFromQuery<T>(string query) { try { HttpClient client = new HttpClient(); System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3; var results = client.GetAsync(query).GetAwaiter().GetResult(); // error happens here return _jsonHelper.DeserializeObject<T>(results.Content.ReadAsStringAsync().GetAwaiter(

Why do dotnet keepalive Http connections fail on the second request with “A connection that was expected to be kept alive was closed by the server.”?

♀尐吖头ヾ 提交于 2021-02-11 14:41:29
问题 I have a dotnet framework application which performs POST api requests to a remote server running Apache. It intermittently fails with the error: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. This occurs on the second request to the server when done over a keepalive TLS connection, and so occurs more frequently in production systems under heavy load and less frequently or not at all in development environments. We have tried:

How I can change configuration of HttpMessageHandler from Polly retry?

十年热恋 提交于 2021-02-11 12:40:49
问题 I have the following issue. I have a proxy set. If a request via proxy very slow or has crashed I would like to try again without proxy. For setting proxy I have the following code in the Startup.cs file: services.AddHttpClient<ICheckPackagesService, CheckPackagesService>(x => { x.Timeout = TimeSpan.FromSeconds(10); }).ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler { Proxy = new WebProxy(IpService.GetIp()) }); But I can't imagine what I have to do for sending new one request

How I can change configuration of HttpMessageHandler from Polly retry?

一个人想着一个人 提交于 2021-02-11 12:40:10
问题 I have the following issue. I have a proxy set. If a request via proxy very slow or has crashed I would like to try again without proxy. For setting proxy I have the following code in the Startup.cs file: services.AddHttpClient<ICheckPackagesService, CheckPackagesService>(x => { x.Timeout = TimeSpan.FromSeconds(10); }).ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler { Proxy = new WebProxy(IpService.GetIp()) }); But I can't imagine what I have to do for sending new one request

response.content.readasstringasync() to object

ぐ巨炮叔叔 提交于 2021-02-10 14:51:45
问题 Hy Guys !! My problem is that i can not extract an object sent by an api, despite i have the schema of the object either in the API or in the client. my code public async Task<ActionResult> Index() { HttpClient client = new HttpClient(); Uri baseAddress = new Uri("http://localhost:44237/"); client.BaseAddress = baseAddress; HttpResponseMessage response = client.GetAsync("api/Front/Subm?IdSubmission=1xxx").Result; try { if (response.IsSuccessStatusCode) { string Result = await response.Content

Accessing .net Core API via azure VM throws ERR_CONNECTION_REFUSED

不羁岁月 提交于 2021-02-10 14:40:43
问题 I've set up a linux VM using Azure and I have the public IP from that machine. I've cloned my repo inside that machine and I run dotnet run and I get the output: Hosting environment: Development Content root path: /home/g67Admin/projeto_integrador_grupo67/mdv Now listening on: https://localhost:5001 Now listening on: http://localhost:5000 Application started. Press Ctrl+C to shut down. Then I try to go to: https://(public IP):5001/api/Drivers and I cannot access it, gives me this error ERR

How do I use FormUrlEncodedContent for complex data types?

十年热恋 提交于 2021-02-10 04:14:33
问题 I need to interact with a third party endpoint that only accepts form encoded payloads. The endpoint wants complex data types at this endpoint, meaning something like this (but form encoded, not JSON): { "foo": "bar", "baz": { "zip": "zap" } } My googling and the docs for the endpoint indicates that this should be form encoded like this: foo=bar&baz[zip]=zap I am using HttpClient and I want to use FormUrlEncodedContent but when I do it is replacing my [] with escaped characters. public class

How do I use FormUrlEncodedContent for complex data types?

这一生的挚爱 提交于 2021-02-10 04:14:08
问题 I need to interact with a third party endpoint that only accepts form encoded payloads. The endpoint wants complex data types at this endpoint, meaning something like this (but form encoded, not JSON): { "foo": "bar", "baz": { "zip": "zap" } } My googling and the docs for the endpoint indicates that this should be form encoded like this: foo=bar&baz[zip]=zap I am using HttpClient and I want to use FormUrlEncodedContent but when I do it is replacing my [] with escaped characters. public class

.net core HTTPS requests returns 502 bad gateway while Postman returns 200 OK

自作多情 提交于 2021-02-08 09:31:32
问题 What's wrong with this code snippet in C#.NET core 3: using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static async Task Main(string[] args) { var uriBuilder = new UriBuilder { Scheme = Uri.UriSchemeHttps, Host = "api.omniexplorer.info", Path = "v1/transaction/address", }; var req = new Dictionary<string, string> { { "addr", "1FoWyxwPXuj4C6abqwhjDWdz6D4PZgYRjA" } }; using(var

http clients that dont throw on error

社会主义新天地 提交于 2021-02-08 08:56:59
问题 I am looking for c# HTTP client that doesn't throw when it gets an HTTP error (404 for example). This is not just a style issue; its perfectly valid for a non 2xx reply to have a body but I cant get at it if the HTTP stack throws when doing a GetResponse() 回答1: All the System.Net.Http.HTTPClient methods that return Task<HttpResponseMessage> do NOT throw on any HttpStatusCode. They only throw on timeouts, cancellations or inability to connect to a gateway. 回答2: If you are using the HttpClient