我想使用基本身份验证Network.HTTP.Conduit
,但无法使其工作。
从文档...
applyBasicAuth :: ByteString -> ByteString -> Request m -> Request mSource
将基本身份验证标头(具有指定的用户名和密码)添加到给定的请求。忽略错误处理:
applyBasicAuth 用户通过 $ fromJust $ parseUrl url
但是当我尝试在一个简单的“Hello World”示例中实现它时:
import Data.ByteString as B
import Network.HTTP.Conduit
import Network.Socket
main :: IO ()
main = withSocketsDo $ do
req <- applyBasicAuth user pass $ fromJust $ parseUrl "http://www.oracle.com"
response <- withManager $ httpLbs req
B.putStrLn $ responseBody response
where
user = B.pack "scott"
pass = B.pack "tiger"
编译失败:不在范围内:fromJust
make fromJust.exe && ./fromJust.exe
ghc --make fromJust.hs
[1 of 1] Compiling Main ( fromJust.hs, fromJust.o )
fromJust.hs:16:37: Not in scope: `fromJust'