Questions tagged [dotnet-httpclient]

1

votes
1

answer
99

Views

Why is my post data all null when posting with HttpClient?

I am trying to post an object from a client web app to a CRUD API for said client. I am using the following code to make the post request: var respP = await _client.PostAsync('api/Persons', new StringContent(JsonConvert.SerializeObject(person), Encoding.UTF8, 'application/json')); And the API action...
ProfK
1

votes
0

answer
129

Views

How do I get the model state from a HTTPRequestResponse from within a console application

I have an APS.NET Core 2.0 API that I am writing a test client for. The test client is a console application. I want to be able to read and display any errors returned from may API call that would be in the model state. In my API, if the model is not valid, I return the model along with a status 422...
EiEiGuy
1

votes
0

answer
124

Views

Mono Invalid IL code in System.Net.Http.HttpClient:.ctor (System.Net.Http.HttpClient): method body is empty

I am trying to get my C# application to run on Mono. Its purpose is to consume as REST WebApi using System.Net.Http.HttpClient. However, when I run it, the Mono .Net runtime throws the following exception: Unhandled Exception:System.InvalidProgramException: Invalid IL code in System.Net.Http.HttpCli...
CreepyTree
1

votes
0

answer
156

Views

How to make Httpclient fail faster when connecting to an invalid endpoint?

We notice that the .NET HttpClient takes atleast ~20 seconds to fail while trying to connect to an endpoint that is invalid. I was wondering if there is a way to make it fail faster, because our back-end services could be moving to different nodes based on criteria such as load etc. We have a mechan...
iambatman
1

votes
1

answer
135

Views

Windows app single sign-on when server has Anonymous and Windows Authentication is enabled?

Our customer has a Web API that is configured for both Anonymous and Windows Authentication. They refuse to make any changes to this configuration. Our C# WinForms application is trying to communicate with this API, but it must use Windows Authentication for the current logged in user. The WebClie...
Hand-E-Food
1

votes
0

answer
50

Views

WPF client dropping REST connections

Update: This is unrelated to WPF, as all clients are failing now. Using WireShark, I see that the server is sending packets but they are not being received by the client, and the server eventually sends an RST packet to kill the connection (which never makes it to the client). WPF seems to be closi...
Ian
1

votes
2

answer
1.6k

Views

Call HttpClient.GetAsync in console application - Deadlock

I searched and saw many posts and I don't know why this simple console call using httpclient.getasync and awaiting it causes it not to complete. here is the code: using System; using System.Net.Http; using System.Threading.Tasks; public class Program { public static void Main(string[] args) { GetAPI...
user3799149
1

votes
1

answer
174

Views

Owin WebApi Post method with Large Object

I am using OWIN to self-host a Web API 2 windows service. It works well most of the time, except for large custom objects which cause an OutOfMemoryException on the client end (winforms app). QUESTION: How do I POST a large custom object? The OutOfMemoryException initially happened at the end of th...
JumpingJezza
1

votes
0

answer
76

Views

HttpClient causes high cpu usage after a request (Xamarin)

I have an out of the box (default template) xamarin forms application that I added a single http get to 'google.com' on a button press. The CPU usage of the app is minimal until I make that web request. At that point it begins to use quite a bit of cpu - probably adding another .1s cpu usage every s...
David Hauck
1

votes
1

answer
553

Views

GET request works in HttpWebRequest,Postman . but not in HttpClient or RestSharp

Following is my request GET /api/v3/countries HTTP/1.1 Host: api-sandbox.grnconnect.com Content-Type: application/json Accept: application/json api-key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX I tried it in postman , and it is working. Also, it works with following code using HttpWebRequest. var httpWebReques...
Toji Thomas
1

votes
0

answer
179

Views

PutAsync Doesn't Send Message Body

I am just trying to send a body with JSON to the server. This is my code. var data = await SerializationAdapter.SerializeAsync(body); var bodyString = Encoding.GetString(data); var length = bodyString.Length; var stringContent = new StringContent(bodyString, Encoding, contentType); stringContent.H...
1

votes
0

answer
85

Views

How to correctly specify proxy with System.Net.HttpClient

Can anyone answer whether or not an HttpClient should be using default proxy if specified within web.config? Whenever I use HttpClient I find myself having to implement a static HttpClientHandler private static HttpClientHandler statichandler = new HttpClientHandler() { Proxy = new WebProxy(Configur...
Jon Selby
1

votes
0

answer
191

Views

HttpRequestMessage is null in HttpClientHandler.ServerCertificateCustomValidationCallback

I am attempting to use the ServerCertificateCustomValidationCallback of HttpClientHandler but the value of the request parameter is always null. Is this expected behavior or do I need to set a bit somewhere? For example the following snippet results in printing Request not defined 4 times. var hand...
Tedford
1

votes
2

answer
899

Views

Send DateTime in Post Request

Hi I have C# (Xamarin) app and .net API. How can I post a DateTime to my .Net API? The .Net API At the moment I have: var formContent = new FormUrlEncodedContent(new[] { new KeyValuePair('Email', u.Email), new KeyValuePair('Password', u.Password), new KeyValuePair('ConfirmPassword', u.ConfirmPasswo...
Steve
1

votes
1

answer
51

Views

Why does do I get a 404 when trying to post content from a zip file vs a normal text file?

I have an MVC cross Web API app that has an ApiFileController, headed: [Produces('application/json')] [Route('api/File')] public class ApiFileController : ApiBaseController It has the following action method [HttpPost('PostDir')] [DisableRequestSizeLimit] public async Task PostDir(string serverPath)...
ProfK
1

votes
2

answer
197

Views

Can I set ConnectionLeaseTimeout for ServicePoint in the application configuration file?

I am using a .NET HttpClient from my application to access a web service. The problem is that the web service is accessed through a ISP load balancer and the application is already installed at the customer (can't updated right now). If the load balancer changes to another ISP, the connection is kep...
Kosmo
1

votes
0

answer
116

Views

Calculate percent of bytes read from compressed HTTP response stream

In my desktop application I process HTTP response from the server and I want to provide a progress of processed bytes relatively to the total response length. I know the content length from the HTTP header but the problem is that a compression (gzip) was applied for the response body. I can calculat...
Igor B
1

votes
1

answer
348

Views

C# RESTful POST with image and body

I am currently trying to POST some data to server to create user profile. The body of RESTful POST has selected image and also other fields. I managed to POST it using Postman. However, I am trying to figure out how to do it using C#. I attempted but it seems that server returns status 500 without m...
oatcrunch
1

votes
0

answer
42

Views

Digest Auth - encoding of email address username

I've made successful calls to a 3rd party API which uses Digest Authentication using Postman. When I attempt to make the same request using an HttpClient, I'm getting 'Unauthorized' back. Using Fiddler to compare the request headers being sent up from Postman vs my code, I can see that my code is at...
George Dando
1

votes
0

answer
169

Views

Xamarin iOS HttpRequestException “Connection reset by peer” on web requests after updating app

We have a self-hosted Apple Enterprise Developer based iOS app that was released around six weeks ago. We're working on the next version of the app and are seeing problems when people update to the new test version. An HttpRequestException is thrown with a 'Connection reset by peer' message whenever...
Tommy Baggett
1

votes
0

answer
14

Views

Force HttpClient or WebRequest to use TLS 1.0 for negative test

With the trend to disable TLS 1.0 at server side, I need a negative test in C#. This should be a single test method among many others that will test other features, and we have parallel tests. Therefore, the global setting at ServicePointManager does not work for me. Is there a way to force TLS 1.0...
fernacolo
1

votes
1

answer
117

Views

Why are my async continuations scheduled outside of the thread pool?

Please read the questions before marking as duplicate. This question implements the solution provided in this question and still experiences a deadlock. I am debugging a large multi-threaded application that makes many concurrent calls to various Google APIs using the .Net client libraries and we ar...
Alden
1

votes
0

answer
298

Views

ASP.NET Core 2.1 HttpClient requesting Google not working on server machine

I am very new to Webprogramming, ASP.NET Core and C#, so maybe my question is easy to answer, but i can't find a solution for my problem :-( I have a working ASP.NET Core 2.1 application and now i am trying to reach an external REST client to get a JSON response. This is working fine on my testing m...
Konrad
1

votes
0

answer
234

Views

Azure function firing httpclient.postasync multiple times within http trigger

I have a Azure function with a http trigger to listen for an incoming web post requests with a JSON payload. When the trigger receives a request I want to parse the json data and call an external restapi based on some of the json data. For some reason the web trigger is posting to the external resta...
thedom4302
1

votes
1

answer
72

Views

Checking the Web API's Response Always Returns 500 Error (without an Error on Server)

Every time I send a request, the response says it had a 500 Server Error. However, I control both sides of this process, and the server is not erroring. Ideas?! Here's how we setup the HttpClient to send the request. BTW, this Client is hosted in Microsoft's Dynamix CRM Online (in case that makes a...
Jesse Sierks
1

votes
2

answer
400

Views

Http connections slow down or deadlock with .NET HttpClient

We have an asp.net webapi application that needs to issue a lot of calls to other web applications (it's basically a reverse proxy). To do this we use the async methods of the HttpClient. Yes, we have seen the hints about using only one HttpClient instance and not to dispose of it. Yes, we have seen...
srudin
1

votes
0

answer
87

Views

System.Net.HttpClient throws COMException when attempting to access internet from corporate domain

I am writing my first UWP app (for Windows 10 only), using Xamarin.Forms. I have written the following test class to establish that I can connect to the internet from my app: public class NetworkInterface { private static readonly System.Net.Http.HttpClient WebClient = new HttpClient(); private void...
occopuyo
1

votes
0

answer
167

Views

Can JSON be sent with HttpClient in C# using the PATCH verb?

I am working with an API that requires a call with the PATCH verb. I am trying to issue a request using the HttpClient object in C#. The request sends, however the JSON is not present in the body. Instead it is blank. Relevant code below. var patch = new HttpMethod('PATCH'); var http = new HttpReque...
Dave
0

votes
0

answer
12

Views

HttpResponseMessage.Content: parse multipart/form-data in .NET Standard

Some service sends me multipart/form-data as a response: using (var response = await HttpClient.SendAsync(request, cancellationToken).ConfigureAwait(false)) { // response.Content is actually in multipart/form-data format } How to parse it in .NET Standard library? Is there some out-of-box class? All...
Dennis
1

votes
0

answer
37

Views

[C#][UWP] How to get full Cookiess of website HTTPS

I'm trying to get cookies of forum: https://forums.voz.vn/ with my Chrome browser. I have 6 cookie values: vfimloggedin. vflastactivity. vflastvisit. vfpassword. vfsessionhash vfuserid. When I use code below: string postData = '&vb_login_username=' + user + '&vb_login_password=' + password + '&cook...
nvcuong1312
1

votes
1

answer
87

Views

Using HttpClientHandler.AutomaticDecompression with WebApplicationFactory.CreateClient()

How to set AutomaticDecompression with using WebApplicationFactory? The example API returns JSON with Content-Encoding: gzip. public class BasicTests : IClassFixture { private readonly WebApplicationFactory _factory; public BasicTests(WebApplicationFactory factory) { _factory = factory; } [Fact] pub...
idubnori
1

votes
1

answer
102

Views

HttpClient POST request with Client Certificate

I'm trying to make a call to a third-party API which requires a client certificate. I generated the client certificate using the SSL tool and uploaded this to the third party site. I have generated a successful POST request through Postman, providing the client certificate through their dialogs. The...
Spodgy
1

votes
0

answer
111

Views

Why Call to WebAPI using C# HttpClient returns 401 while it is working using Postman?

Here is WebAPI EndPoint: https://mysoylplus-apptest.frontierag.co.uk/api/someendpoint I am sending formData in Postman in key-value pair like below: authenticationData[b64EncryptedSoylSenseInfo] : 'somekey', authenticationData[b64iv] : 'some key' The above thing is working in Postman but when I use...
deepak vajpayee
1

votes
0

answer
65

Views

Security protocol per httpclient/request (HttpClient)

I have the same problem as in this question. var handler = new WebRequestHandler(); handler.ClientCertificates.Add(cacert2); var client = new HttpClient(handler, true); var result = await client.PostAsync(uri, content); //tls 1.0 This request to the service works only with default SecurityProtocol (...
vusaldev
1

votes
1

answer
56

Views

HttpClient hangs with concurrent tasks

I have about 1000 requests that I'm making when my application starts. After calling ~200 requests, only ~10 are returned and then my application hangs and no more results are returned. Here is what my code looks like: // File1.cs await Task.WhenAll(allUsers.Select(user => Connect(user))); // File2...
CodingMadeEasy
1

votes
1

answer
103

Views

HttpClient. Default credentials to authenticate on auto discovered proxy

Control freak disclaimer: yes, there are a lot of questions about HttpClient and proxy, but they use at least one of explicite (non default) proxy credentials explicite (non WPAD) proxy configuration deprecated Api, e. g. WebProxy.GetDefaultProxy, WebRequest and so on. According to dotnet developers...
SerG
1

votes
3

answer
164

Views

.Net HttpClient Invalid URI: The Uri string is too long

The below code is used to send emails through the pardot api. if (ConfigurationManager.AppSettings.Count > 0) { uri = ConfigurationManager.AppSettings['PardotURI'].ToString() + 'email/version/4/do/send/prospect_email/' + email; uri += '?user_key=' + ConfigurationManager.AppSettings['PardotUserKey']...
Matthew Duckworth
1

votes
0

answer
73

Views

Forward ASP.Net WebAPI request to another API

I am trying to forward request from one API to another one like this: protected Task ForwardRequestToSomeApi() { string forwardUri = 'https://some.api' + Request.RequestUri.PathAndQuery; Request.Headers.Remove('Host'); Request.RequestUri = new Uri(forwardUri); if (Request.Method == HttpMethod.Get) {...
Vasyl Senko
1

votes
1

answer
50

Views

How to access [Authorize] controller actions using HttpClient with Bearer token? Getting 401 “The audience is invalid”

There are four clients within the application: angular.application - resource owner identity_ms.client - webapi app (.net core 2.1) IdentityServer4 with AspNetIdentity AccountController with shared actions to register users, reset password etc. UserController with secured actions. The Data action of...
FridensonDev
1

votes
0

answer
29

Views

PostAsJsonAsync does not return response and eventually times out

I have an MVC website that makes an API call using a HttpClient. I configured the timeout to be 2 minutes and the API call generally returns within 90 seconds. I can see from application logging that the API completes its execution. If I also call the API method using a tool like Postman or SOAPUI I...
Jordan Schofield

View additional questions