I want to use Basic Authentication from Network.HTTP.Conduit
and cannot make it work.
From the documentation...
applyBasicAuth :: ByteString -> ByteString -> Request m -> Request mSource
Add a Basic Auth header (with the specified user name and password) to the given Request. Ignore error handling:
applyBasicAuth user pass $ fromJust $ parseUrl url
But when I try to implement that in a simple "Hello World" example:
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"
Compilation fails with: Not in scope: 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'
"Not in scope: fromJust" means that the compiler cannot find fromJust
, since it's not defined in your module, or in any of your imported modules (including the Prelude, which is imported automatically by default).
You need to import it yourself from the correct module. You can find out which one using Hoogle.
In this case, you need to import Data.Maybe
.