问题标签 [flurl]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
5356 浏览

.net - Flurl.Http 自定义错误

我正在制作一个客户端向服务器发出请求的应用程序。服务器使用 node.js 编写,客户端使用 flurl.Http 编写在 .NET 中。

当服务器上的请求失败时,创建自定义错误消息总是有用的。像这样的东西:

但是,这会在客户端调用 FlurlHttpException,并且响应中的 JSON 信息会丢失。

从服务器接收到不成功的响应代码时,如何接收此 JSON 信息?

0 投票
1 回答
1109 浏览

c# - 命名空间 Flurl 中不存在类型或命名空间 Http

开始一个新的可移植类库项目,我添加了Flurl.Http NuGet 包,这似乎也降低了它的所有依赖项,正如预期的那样。

但是,当我添加 using Flurl.Http 指令和一些简单的代码时,例如

我得到编译错误

命名空间“Flurl”中不存在类型或命名空间名称“Http”(您是否缺少程序集引用?)

奇怪的是,智能感知识别 .Http 命名空间或扩展方法(PostUrlEncodedAsync)没有问题

在这个最基本的 PCL 项目中,我可能缺少什么?

也许我的 package.config 文件会很有价值,所以这里也是:

0 投票
2 回答
2382 浏览

portable-class-library - 如何在 Flurl HttpClient 中保留标头

我在 .NET Http 客户端上使用 Furl.Http 包装器。对于每个请求,我的 API 都需要发送一个 User-Agent 和一个 Authorization 标头。

我想设置一次,而不是每次都声明。

我认为我能够做的是创建 FlurlClient 的实例并在其上设置标头,然后在每个请求之前 ResetToRoot,如以下示例代码所示:

但是,似乎在RestToRoot()不再发送标头之后。

这是设计使然吗?是否有更好的方法来确保在每个请求上发送这些标头?

0 投票
3 回答
41846 浏览

c# - 无法设置 Content-Type 标头

我在 HttpClient 上设置 Content-Type 时遇到问题。我跟着这个问题:How do you set the Content-Type header for an HttpClient request? 但仍然没有运气。

调试器 我也尝试过使用 Flurl 库,但在尝试添加“Content-Type”时它会崩溃。

那么我该如何强制它才能真正添加​​它呢?提前致谢。

0 投票
5 回答
5397 浏览

c# - 如何使用 FluUrl 进行 XML POST

FluUrl在处理 Json/UrlEncoded 请求方面做得很好。但是,文档并没有真正指出如何处理其他请求类型,例如text/xml.

使用 FluUrl 进行 XML POST 的最佳方式是什么?

这(访问底层HttpClient)有点违背了使用 FluUrl 的目的,因为您需要再次构建 URI 和内容:

0 投票
2 回答
7063 浏览

c# - C# Flurl and HttpClient, no response from REST API

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 the object "EnrollmentRequestDto"

After this object is created I send to to my class RequestHandler and the method BulkEnrollRequest, which atm is written with HttpClient extension Flurl, which can be found here: github

I have also tried this to make sure that nothing happens in Flurl(This is just to debug to the point where I want to get the response):

And the code freezes at the await point and nothing is happening. I have tried to place a breakpoint after the BulkEnrollRequest so it never leaves this method.

Now here's for the funny part: It did work while I was working on the ErrorHandler and at some point the API just stopped responding. Wireshark shows that a request is being made... so I am stuck.

Any help is appreciated.

EDIT

This now works! I implemented async all the way from the API Controller down to RequestHandler, then awaited for every call. For reference:

0 投票
1 回答
3174 浏览

rest - 如何将内容标题添加到 Flurl

我想知道如何将内容标题添加到 flurl 语句中。onedrive 实现要求我向内容添加内容类型标头,并尝试了所有可能的解决方案,但没有成功。

我被迫使用带有以下代码的常规 httpclient。

我已经尝试过 Flurl 的常规 PutJsonAsync 方法,但没有运气。这是我的代码中剩下的唯一非 Flurl 部分。

提前谢谢。

0 投票
1 回答
479 浏览

owin - 是否可以将 Furl.Http 与 OWIN TestServer 一起使用?

我正在使用 OWIN TestServer,它为我提供了一个 HttpClient 来对测试服务器进行内存调用。我想知道是否有一种方法可以传入现有的 HttpClient 供 Flurl 使用。

0 投票
2 回答
2044 浏览

c# - Flurl.http PostJsonAsync 消失

我有一个发布到 API 的类,该 API 在我的单元测试中工作,但不是我的 MVC 控制器。

在测试器中,以下行工作得很好,但是在我的 MVC 应用程序中调用它时,我无法超越以下行。

0 投票
0 回答
1311 浏览

ssl-certificate - 在 Xamarin 中使用 Flurl 忽略 SSL 错误

我想让 Flurl 和底层的 HttpClient 库忽略 SSL 错误,这样我就可以在本地开发。

具体来说,我有一个需要 SSL 证书的 web api。我创建了一个临时的,以便可以在本地进行开发,但是 Flurl 和 HttpClient 在 SSL 检查时返回错误。

如何禁用 SSL 错误检查?