问题标签 [wreq]

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 投票
1 回答
160 浏览

http - haskell wreq 参数列表

在优秀的wreqHaskell 库中,很容易将一个或多个查询参数添加到 URL:

opts = defaults & param "key" .~ ["value"]

但是我正在努力做的是一次添加一个参数列表

params = [("key1", "value1"), ("key2", "value2"), ("key3", "value3")]

我知道有功能params,但我找不到任何关于如何使用它的例子。

0 投票
1 回答
317 浏览

json - 使用 wreq 作为 x-www-form-urlencoded 的内容类型发送请求

这个周末我正在学习使用 wreq,但我遇到了一些奇怪的行为。

我有一个模块AuthRequest

和一个模块HttpDemo

另一方面,我有一个简单的 python 烧瓶服务器,它通过断点侦听这个请求,这样我就可以看到通过的值。

当我查看request.form服务器端时,我看到:ImmutableMultiDict([('{"client_secret":"some_secret","client_id":"some_id","grant_type":"whatever"}', '')])

关键是我的帖子正文应该是什么!

但是,如果我使用 requests python 库发出类似的请求

我看到了我的期望:ImmutableMultiDict([('grant_type', 'whatever'), ('client_id', 'some_id'), ('client_secret', 'some_secret')])

我想我想要的是将此请求发送为x-www-form-urlencoded. 我看到这里有一些文档,但不清楚如何进行。也许我需要一个 FormValue 实例?一个例子会很有帮助。

0 投票
1 回答
209 浏览

haskell - 如何使用 Scotty 在前端显示来自 HTTP GET 请求的响应?

我是第一次尝试 Scotty,但我似乎无法摆脱我的 GET 请求。响应作为类型返回

我知道我需要将它转换为 Scotty 可以输出的类型,但我不知道该怎么做。

我的完整代码是:

我尝试使用 LiftIO,但这仍然给我一个类型错误。我想知道我应该如何准确地转换我的响应,以便我可以在前端显示它,就像我用 html 显示我的初始“Hello World”一样。

0 投票
1 回答
186 浏览

haskell - Haskell / Wreq - Advice on complicated type signatures for http requests

I'm a Haskell beginner and am currently using wreq to make a simple wrapper around an api. I want to send an if-modified-since header if provided with a time. I am doing so in the following manner.

I noticed that 304 (not modified) responses are coming back as exceptions so that was my justification for using the Either type. I wanted to provide visibility to errors for people that might use this api wrapper.

Assuming the request is successful, I want to parse the response body into a corresponding type defined in my library. There is a chance deserialization might not work correctly if something changes on the server I'm making requests to so I chose to use the Maybe type to account for this.

The signatures of these functions are starting to seem like an eyesore to me, something in my gut is telling me there is a better way but I am unsure. One thing I did was make another function to put them together with the hopes it would be easier to use. This is the function I plan on using to create other functions to make more specific requests to individual resources.

I now have to deal with 3 layers of structure when dealing with an http request. IO, Either, and Maybe. Am I making this too complicated? What can I do to make this less of a pain to work with from a usage and maintainability perspective? How can I improve this?

0 投票
1 回答
231 浏览

json - 解析 JSON haskell

我正在尝试访问Object我的请求中的内部。这是我的代码:

这是我的结果:

我正在尝试访问“结果”键的对象,然后访问其中的值。我不知道该怎么做,我已经搞砸了 AESON 和提供的^?运营商,wreq但它对我不起作用。

0 投票
1 回答
75 浏览

haskell - 我应该如何在 Haskell 中从多个网络请求创建数据结构

我是 Haskell 的新手,所以提前为这个可能愚蠢的问题道歉。

我想构建一个由我的应用程序中的两个 http 请求构建的数据结构。

我的第一个请求获得了我可以选择的基本用户decode列表Maybe [User]

但是,如果我想通过为每个通过执行类似操作来响应的用户调用第二个端点来丰富我的用户数据

我现在不能把这些部分拼凑在一起。我在一个do街区里,期待着IO ()

任何帮助,将不胜感激!

0 投票
0 回答
391 浏览

haskell - 堆栈安装导致错误“无法满足-package-id ...”

我在我的 MacOS El Captain 上使用最新的 Haskell Platform 8.2.2。

当我创建一个新项目并安装wreq时,我会收到以下错误


我的环境:

0 投票
1 回答
150 浏览

haskell - 控制 Monad (when 等) 和非 IO() 返回类型

我正在尝试在我的程序中使用“何时”功能,因为如果某事是真的,我想执行一个动作,而不是如果它不是真的。我也可以通过使用 Maybe monad 来完成同样的事情,但这会使我的程序的其余部分变得混乱。

问题是,当期望返回类型为 IO() 但我想让它(或我自己的版本)适用于 IO(Response ByteString)

到目前为止,这是我的功能代码:

编辑:“打印”潜入我最初发布的代码中,这是我尝试过的东西,我已经删除了它。我可以使用 print,但是我还需要使用 foreign.marshall 中的 unsafeLocalState,这是不可取的吗?在这种情况下,代码将变得相同,但使用 when hasRel (print $ unsafeLocalState (post addr ("dummy" := details)))

0 投票
1 回答
151 浏览

json - 使用 wreq 在 Haskell 中遍历 JSON - 关键问题

我正在尝试遍历从 OpenWeatherMap API 获得的一些 JSON 响应,但在检索一些值时遇到了一些问题。这是我的代码:

问题是只返回“cod”的值(在这种情况下为“200”)。""如果我们尝试使用 London,GB, Chicago, US(例如),“name”和“id”的值显示为。然而响应体看起来像:

我一开始以为是类型不匹配,但Int那里有 200 个(除非我弄错了?)所以我不确定问题出在哪里?""似乎表明这两个键 (idname) 不存在,但它们确实存在。

有任何想法吗?提前致谢。

0 投票
1 回答
164 浏览

haskell - 如何使用 Wreq 设置 HTTP 请求正文?

customMethod 使用https://hackage.haskell.org/package/wreq-0.5.2.1/docs/Network-Wreq.html#v:customMethod时如何设置请求正文?

postput接受主体的参数,但是没有这样的参数customMethod