Reputation:
I need to add a header and send a request:
import Network.HTTP.Conduit
import qualified Data.ByteString.Char8 as C8
--..........
res <- withManager $ httpLbs $ createReq request
return ()
where
createReq r = r {
--...........
requestHeaders = ("content-type", "application/json") : requestHeaders r
}
I've got 2 errors:
Couldn't match type `[Char]'
with `case-insensitive-1.0.0.1:Data.CaseInsensitive.CI
C8.ByteString'
Expected type: HeaderName
Actual type: [Char]
In the expression: "content-type"
In the first argument of `(:)', namely
`("content-type", "application/json")'
In the `requestHeaders' field of a record
Couldn't match expected type `C8.ByteString'
with actual type `[Char]'
In the expression: "application/json"
In the first argument of `(:)', namely
`("content-type", "application/json")'
How do I solve them?
UPDATE:
C8.pack
doesn't, it causes other errors.
Upvotes: 0
Views: 186
Reputation: 43309
As the error suggests, the compiler expects a type Data.CaseInsensitive.CI C8.ByteString
, while you provide it with [Char]
(aka String
).
I suspect your problem is caused by the missing OverloadedStrings
extension, which enables arbitrary types to be constructed from string literals. To fix this add the following line in the beginning of your module:
{-# LANGUAGE OverloadedStrings #-}
Upvotes: 3