Tag: flurl

如何更改FLURL客户端的HTTP请求内容类型?

我正在使用flurl提交HTTP请求,这非常有用。 现在我需要将一些请求的“ Content-Type”标题更改为“application / json; odata = verbose” public async Task 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(); } private IFlurlClient GetBaseUrlForOperations(string resource) { var url = _azureApiUrl .AppendPathSegment(“api”) .AppendPathSegment(resource) .WithOAuthBearerToken(AzureAuthentication.AccessToken) .WithHeader(“x-ms-version”, “2.11”) .WithHeader(“Accept”, “application/json”); return url; } […]

C#Flurl – 将WebRequestHandler添加到FlurlClient

我正在与Flurl合作,以获得需要基于证书的身份validation的API。 我从这篇SOpost中看到,向WebRequestHandler添加证书并指示HttpClient使用此处理程序很容易。 但是,使用Flurl对我来说并不是那么清楚。 我尝试了以下三件事。 扩展DefaultHttpFactory 我首先怀疑我需要创建自己的X509HttpFactory : DefaultHttpFactory ,它将创建处理程序并将其分配给HttpClient 。 但是,在查看源代码时,我注意到CreateClient的构造函数已经需要一个处理程序。 这个处理程序来自哪里? 使用DefaultHttpFactory创建客户端 WebRequestHandler handler = new WebRequestHandler(); handler.ClientCertificates.Add(myX509Cert); var clientFactory = new DefaultHttpClientFactory(); FlurlClient fc = clientFactory.CreateClient(url, handler); 由于HttpClient无法转换为FlurlClient因此无法编译 使用ConfigureHttpClient var clientFactory = new DefaultHttpClientFactory(); FlurlClient fc = new Url(“foobar.com”).ConfigureHttpClient(client => client = clientFactory .CreateClient(url, handler)); 这似乎是最可行的选项,但我不确定,因为委托是一个没有返回类型的Action 。 问题 使用Flurl支持客户端证书身份validation的最佳/正确方法是什么?