如何通过GET请求传递数据?

时间:2019-04-17 12:03:22

标签: clojure http-kit cheshire

我想通过GET请求传递表单数据。

我成功地做到了: curl http://sample.com -d 'action=login_request&user_name=balvan'

但是我需要从-d传递相同的内容。通过此函数调用:

(http-client/request
                             {:url             base-url
                              :method          :get
                              :deadlock-guard? false
                              :insecure?       true})

如何在请求正文中添加那些“ -d”参数?

我在ns声明中有[org.httpkit.client :as http-client],在项目的依赖项中有[cheshire "5.8.1"]

1 个答案:

答案 0 :(得分:1)

发出man curl告诉我们-d标志将发送带有数据的发布请求。

-d, --data <data>
    (HTTP)  Sends  the  specified data in a POST request to the HTTP
    cause curl to pass the data to the server using the content-type
    -d, --data is the same as --data-ascii. --data-raw is almost the
    ter...

您想要做的是:

(http-client/request
  {:url              base-url
   :method           :post
   :form-params      {"action" "login_request"
                      "user_name" "balvan"}
   :deadlock-guard?  false
   :insecure?        true})