http - 使用参数发出简单的 post 请求并接收响应

标签 http networking haskell

我想复制此功能:

curl -d "user=username&passwd=passwd&api_type=json" http://www.reddit.com/api/login/username

我至少遇到过 3 个以迂回方式提供此功能的库:http-conduitnetwork-httpcurl 。发出 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/

相关文章:

java - 如何在java中发送带有post参数的简单http post请求

javascript - 获取连接到网络的设备的基本信息

arrays - 如何从一维数组中创建一个二维未装箱数组?

haskell 枚举 - 如果值构造函数需要值而不是空值,该怎么办?给出需求场景

c - 如何绕过阻止直接连接的网站?

java - Apache 尼菲 : ListenHTTP vs HandleHTTPRequest

java - 如何根据条件更改 HttpServlet 的服务器/主机

vb.net - 读取异步网络流

windows - 如何在没有路由器/DNS 的情况下使用以太网将 2 台 PC 快速连接在一起

haskell - 如何绑定(bind)两个 IO () monad 而不执行它们?