我正在尝试使用自定义标头创建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?
答案 0 :(得分:2)
http-conduit根本不使用HTTP包,它们完全是两种不同的方法。如果您查看http-types文档,您会发现Header
只是标题名称和值的元组。
custom_header
无效的唯一原因是您需要启用OverloadedStrings
语言扩展程序。