flurl

Can I use FlurlClient with Asp.Net Core TestServer?

Deadly 提交于 2019-12-11 08:48:38
问题 We are using FlurlClient in a few projects and familiar with their fluent interface. We now want to use it in asp.net core integration tests using TestServer. The example from http://asp.net-hacker.rocks/2017/09/27/testing-aspnetcore.html _server = new TestServer(new WebHostBuilder() .UseStartup<Startup>()); _client = _server.CreateClient(); I was going to change code to _server = new TestServer(new WebHostBuilder() .UseStartup<Startup>()); var httpClient = _server.CreateClient(); _client =

C# Flurl and HttpClient, no response from REST API

夙愿已清 提交于 2019-12-08 17:38:05
问题 I am having a problem with getting a response from an API with my code, the request does not time out and it does not give me a response at all. I have made an api endpoint in my own API to return the json string to then manually post the json data with "Firefox Poster" and it works just fine. With this I believe that the problem is somewhere in my code. I got a C# WebAPI which I am developing to be used with an Angular frontend(This works, it's just for history). When calling my API I create

Can't set Content-Type header

半世苍凉 提交于 2019-12-08 16:03:12
问题 I'm having trouble setting the Content-Type on HttpClient. I followed along this question: How do you set the Content-Type header for an HttpClient request? But still no luck. String rcString = JsonConvert.SerializeObject(new RoadsmartChecks() { userguid = user_guid, coords = coordinates, radius = (radius * 100) + "" }, ROADSMART_JSON_FORMAT, JSONNET_SETTINGS); HttpClient c = new HttpClient(); c.BaseAddress = new Uri(BASE_URL); c.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type",

Posting `multipart/form-data` with Flurl

为君一笑 提交于 2019-12-07 10:26:48
问题 I am in need to post the following request: POST http://target-host.com/some/endpoint HTTP/1.1 Content-Type: multipart/form-data; boundary="2e3956ac-de47-4cad-90df-05199a7c1f53" Accept-Encoding: gzip, deflate Connection: Keep-Alive Content-Length: 6971 Host: target-host.com --2e3956ac-de47-4cad-90df-05199a7c1f53 Content-Disposition: form-data; name="some-label" value --2e3956ac-de47-4cad-90df-05199a7c1f53 Content-Disposition: form-data; name="file"; filename="my-filename.txt" <file contents>

POST JSON with Flurl

半世苍凉 提交于 2019-12-06 05:19:25
I start with Flurl and I would like to create a POST but I think I have a problem with the format of my JSON parameters. You can see the JSON parameters: { "aaaUser" : { "attributes" : { "name" : "device:domain\\login", "pwd" : "123456" } } } These settings work with Postman and now I would like to use Flurl to continue my little POST :) But my JSON format is not correct. using System.Threading.Tasks; using Flurl.Http; namespace Script { class Program { static async Task Main(string[] args) { var result = await "https://IP/api/aaaLogin.json".PostUrlEncodedAsync(new { name = "device:domain\

Posting `multipart/form-data` with Flurl

筅森魡賤 提交于 2019-12-05 14:33:35
I am in need to post the following request: POST http://target-host.com/some/endpoint HTTP/1.1 Content-Type: multipart/form-data; boundary="2e3956ac-de47-4cad-90df-05199a7c1f53" Accept-Encoding: gzip, deflate Connection: Keep-Alive Content-Length: 6971 Host: target-host.com --2e3956ac-de47-4cad-90df-05199a7c1f53 Content-Disposition: form-data; name="some-label" value --2e3956ac-de47-4cad-90df-05199a7c1f53 Content-Disposition: form-data; name="file"; filename="my-filename.txt" <file contents> --2e3956ac-de47-4cad-90df-05199a7c1f53-- I can do this really easily with Python requests library as

Disable AutoRedirect in FlurlClient

不想你离开。 提交于 2019-12-05 08:58:41
I am using FlurlHttp and I want to disable AllowAutoRedirect for some API calls. I know How can I get System.Net.Http.HttpClient to not follow 302 redirects? WebRequestHandler webRequestHandler = new WebRequestHandler(); webRequestHandler.AllowAutoRedirect = false; HttpClient httpClient = new HttpClient(webRequestHandler); // Send a request using GetAsync or PostAsync Task<HttpResponseMessage> response = httpClient.GetAsync("http://www.google.com") But for Flurl I found only the way similar to described in C# Flurl - Add WebRequestHandler to FlurlClient (I haven't compiled yet the code below ,

Flurl client lifetime in ASP.Net Core 2.1 and IHttpClientFactory

半城伤御伤魂 提交于 2019-12-04 03:53:18
Flurl states that using singleton client is recommended pattern: HttpClient is intended to be instantiated once and re-used throughout the life of an application. Especially in server applications, creating a new HttpClient instance for every request will exhaust the number of sockets available under heavy loads. This will result in SocketException errors. But since Asp.Net Core 2.1 there are updated rules for HttpClient lifetime in Net Core 2.1 . When you use the HttpClientFactory to request a HttpClient, you do in fact get a new instance each time, which means we don’t have to worry about

How to change the HTTP Request Content Type for FLURL Client?

爷,独闯天下 提交于 2019-12-01 17:41:29
问题 I am using flurl to submit HTTP request and this is very useful. Now I need to change the " Content-Type" header for some of the requests to "application/json;odata=verbose" public async Task<Job> AddJob() { var flurlClient = GetBaseUrlForGetOperations("Jobs").WithHeader("Content-Type", "application/json;odata=verbose"); return await flurlClient.PostJsonAsync(new { //Some parameters here which are not the problem since tested with Postman }).ReceiveJson<Job>(); } private IFlurlClient

How to change the HTTP Request Content Type for FLURL Client?

北慕城南 提交于 2019-12-01 17:39:31
I am using flurl to submit HTTP request and this is very useful. Now I need to change the " Content-Type" header for some of the requests to "application/json;odata=verbose" public async Task<Job> AddJob() { var flurlClient = GetBaseUrlForGetOperations("Jobs").WithHeader("Content-Type", "application/json;odata=verbose"); return await flurlClient.PostJsonAsync(new { //Some parameters here which are not the problem since tested with Postman }).ReceiveJson<Job>(); } private IFlurlClient GetBaseUrlForOperations(string resource) { var url = _azureApiUrl .AppendPathSegment("api") .AppendPathSegment