http-conduit-1.9.4中的requestHeaders

时间:2013-07-07 07:18:06

标签: haskell http-request

我正在尝试使用自定义标头创建http请求(使用http-conduit-1.9.4):

req <- parse "https://some_url"
let request = req { requestHeaders = [customHeader] }

我不明白应该是什么样的customHeader? 我试过了

import Network.HTTP.Headers
let custom_header = mkHeader (HdrCustom "Some-Header") "Some-Value"

但发生了错误

Couldn't match expected type `Network.HTTP.Types.Header.Header'
                with actual type `Header'
    In the expression: custom_header
    In the `requestHeaders' field of a record
    In the expression: req {requestHeaders = [custom_header]}

我也尝试过

let custom_header = ("Some-Header", "Some-Value")

和错误

Couldn't match expected type `Network.HTTP.Types.Header.HeaderName'
                with actual type `[Char]'
    In the expression: "User-Agent"
    In the expression: ("User-Agent", "erthalion")
    In the `requestHeaders' field of a record

那么,有谁知道应该是customHeader?

1 个答案:

答案 0 :(得分:2)

http-conduit根本不使用HTTP包,它们完全是两种不同的方法。如果您查看http-types文档,您会发现Header只是标题名称和值的元组。

custom_header无效的唯一原因是您需要启用OverloadedStrings语言扩展程序。