2017-10-13 57 views
0

我試圖創建一個Http.Request值:缺少Http.Request的參數是什麼?

request : Http.Request 
request = 
    { verb = "POST" 
    , headers = 
     [ ("Origin", "http://elm-lang.org") 
     , ("Access-Control-Request-Method", "POST") 
     , ("Access-Control-Request-Headers", "X-Custom-Header") 
     ] 
    , url = url 
    , body = body 
    } 

的代碼被嵌入在下面的功能:

tryRegister : Form -> (Result Http.Error JsonProfile -> msg) -> Cmd msg 
tryRegister form msg = 
    let 
     url = 
      baseUrl ++ "register" 

     body = 
      encodeRegistration form |> Http.jsonBody 

     request : Http.Request 
     request = 
      { verb = "POST" 
      , headers = 
       [ ("Origin", "http://elm-lang.org") 
       , ("Access-Control-Request-Method", "POST") 
       , ("Access-Control-Request-Headers", "X-Custom-Header") 
       ] 
      , url = url 
      , body = body 
      } 
    in 
     Http.send msg request 

我收到以下錯誤:

Type Http.Request has too few arguments. - Expecting 1, but got 0.

Http.Request缺少什麼論點?

附錄:

http://package.elm-lang.org/packages/evancz/elm-http/3.0.1/Http

回答

3

你的附錄的鏈接是一個老版本中的HTTP包。新套件是elm-lang/http。 Request預期的類型參數是成功響應中使用的類型,在您的情況下,它應該是JsonProfile

2

evancz/elm-http軟件包已過時,您可能實際上正在使用elm-lang/http,因此您正在查看錯誤的文檔。

要使用elm-lang/http構造Http.Request,您需要調用Http.request函數並將它傳遞給描述請求的記錄。 http://package.elm-lang.org/packages/elm-lang/http/1.0.0/Http#request

另外,你實際上不能從瀏覽器中設置的「原產地」的請求頭,這意味着你將不再需要在所有設置任何頭和可以只使用Http.post輔助函數http://package.elm-lang.org/packages/elm-lang/http/1.0.0/Http#post