无法将参数传递给Network.HTTP.Simple中的httpLBS

时间:2017-09-11 17:01:09

标签: haskell request httpclient

我无法弄清楚为什么以下代码有效:

main = do
    response <- httpLBS "http://httpbin.org/get"
    let statusCode = show $ getResponseStatusCode response
    putStrLn statusCode

但这不是:

getStatusCode url = do
 response <- httpLBS url
 let statusCode = show $ getResponseStatusCode response
 putStrLn statusCode

当调用getStatusCode "http://httpbin.org/get"时,我收到以下错误:

<interactive>:38:15: error:
    * Couldn't match expected type `Request' with actual type `[Char]'
    * In the first argument of `getStatusCode', namely
        `"http://httpbin.org/get"'
      In the expression: getStatusCode "http://httpbin.org/get"
      In an equation for `it':
          it = getStatusCode "http://httpbin.org/get"

错误消息似乎暗示httpLBS需要Request类型。但我无法弄清楚为什么第一个在这种情况下起作用。

0 个答案:

没有答案