首页 > 解决方案 > 如何使用 GET 请求传递数据?

问题描述

我想通过 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”参数?

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

标签: clojurehttp-kitcheshire

解决方案


发布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})

推荐阅读