我试图将此curl请求转换为HTTP-Conduit:
curl -v https://api.sandbox.paypal.com/v1/identity/openidconnect/userinfo/?schema=openid -H "Content-Type:application/json" -H "Authorization:Bearer -AxLVv0fegyk-opT.2sG5JGQ3VNHUL08WpWkO3s7tVI"
我的haskell代码是:
{-# LANGUAGE OverloadedStrings #-}
import Network.HTTP.Conduit
import Data.ByteString.Char8
import qualified Data.ByteString.Lazy as L
import Network.HTTP.Types.Header
import Network (withSocketsDo)
import Control.Failure
import Network.HTTP.Types
getReq :: Failure HttpException m => m Request
getReq = parseUrl "https://api.sandbox.paypal.com/v1/identity/openidconnect/userinfo/?schema=openid"
getRequestHeaders :: RequestHeaders
getRequestHeaders = [ ( "Content-Type" , "application/json")
, ( "Authorization" , "Bearer -AxLVv0fegyk-opT.2sG5JGQ3VNHUL08WpWkO3s7tVI")
]
main :: IO ()
main = do
req0 <- getReq
let req = req0 { method = methodPost
, requestHeaders = getRequestHeaders
}
res <- withManager $ httpLbs req
L.putStrLn $ responseBody res
运行main时出现此错误:
*** Exception: TlsException (HandshakeFailed (Error_Packet_unexpected "Alert [(AlertLevel_Fatal,DecryptError)]" " expected: change cipher"))
任何帮助?
更新:
运行
cabal list --installed HTTP-Conduit
cabal list --installed tls
得到我的回复
* http-conduit
Synopsis: HTTP client package with conduit interface and HTTPS support.
Default available version: 2.0.0.4
Installed versions: 1.9.4.5
Homepage: http://www.yesodweb.com/book/http-conduit
License: BSD3
* http-client-tls
Synopsis: http-client backend using the connection package and tls library
Default available version: 0.2.0.3
Installed versions: 0.2.0.3
Homepage: https://github.com/snoyberg/http-client
License: MIT
* tls
Synopsis: TLS/SSL protocol native implementation (Server and Client)
Default available version: 1.2.2
Installed versions: 1.1.5
Homepage: http://github.com/vincenthz/hs-tls
License: BSD3
* tls-extra
Synopsis: TLS extra default values and helpers
Default available version: 0.6.6
Installed versions: 0.6.5
Homepage: http://github.com/vincenthz/hs-tls
License: BSD3
我运行cabal安装来更新两个tls,http-conduit并且仍然遇到同样的错误。