ube*_*ben 3 http-get http-post request payload elm
Http.requestbody该方法似乎忽略了GETinit : () -> ( Model, Cmd Msg )
init _ =
( Loading
, Http.request
{ method = "GET"
, headers = []
, url = "http://127.0.0.1"
, body = Http.stringBody "text/plain" "Hello World!"
, expect = Http.expectWhatever Sent
, timeout = Nothing
, tracker = Nothing
}
)
Run Code Online (Sandbox Code Playgroud)
发送的请求没有正文(使用浏览器开发工具检查时)。
init : () -> ( Model, Cmd Msg )
init _ =
( Loading
, Http.request
{ method = "POST" {- CHANGED TO POST -}
, headers = []
, url = "http://127.0.0.1"
, body = Http.stringBody "text/plain" "Hello World!"
, expect = Http.expectWhatever Sent
, timeout = Nothing
, tracker = Nothing
}
)
Run Code Online (Sandbox Code Playgroud)
但是方法一改"POST",就有效了!体内含有"Hello World!".
我尝试与之通信的 API 需要请求application/json中包含正文GET。帮我 !
PS:这是文档的内容:
emptyBody : Body为您的请求创建一个空正文。这对于不发送任何数据的 GET 请求和 POST 请求很有用。
这还不清楚,因为它可以用两种不同的方式解释:
这对于 GET 请求和{不发送任何数据的 POST 请求}很有用。
或者:
这对于不发送任何数据的 { GET 请求和 POST 请求 } 很有用。