我想复制此功能:
curl -d "user=username&passwd=passwd&api_type=json" http://www.reddit.com/api/login/username
我至少遇到过 3 个以迂回方式提供此功能的库:http-conduit
、network-http
和 curl
。发出 http 请求的标准是什么库?我将如何使用它来发出此 post 请求?
我应该指定我也想阅读回复。
最佳答案
标准库是HTTP 。它随 Haskell 平台一起提供。
The HTTP package supports client-side web programming in Haskell. It lets you set up HTTP connections, transmitting requests and processing the responses coming back, all from within the comforts of Haskell. It's dependent on the network package to operate, but other than that, the implementation is all written in Haskell.
A basic API for issuing single HTTP requests + receiving responses is provided. On top of that, a session-level abstraction is also on offer (the BrowserAction monad); it taking care of handling the management of persistent connections, proxies, state (cookies) and authentication credentials required to handle multi-step interactions with a web server.
The representation of the bytes flowing across is extensible via the use of a type class, letting you pick the representation of requests and responses that best fits your use. Some pre-packaged, common instances are provided for you (ByteString, String.)
如果 HTTP 包由于某种原因不适合,正如您所指出的,Hackage 上有很多包,包括直接curl 绑定(bind)、各种高级绑定(bind)以及注重性能的绑定(bind)。
关于http - 使用参数发出简单的 post 请求并接收响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10609405/