【问题标题】:httpkit-fake does not intercept url build with passed parametershttpkit-fake 不拦截带有传递参数的 url 构建
【发布时间】:2017-03-29 19:28:26
【问题描述】:

如何让with-fake-http 拦截包含:query-params 的http/get 请求。以下代码产生异常

 (require                                                                                                                                                                                                                                                                      
            '[org.httpkit.client :as http]                                                                                                                                                                                                                                      
            '[org.httpkit.fake :refer :all]                                                                                                                                                                                                                                     
            )      


(with-fake-http ["localhost?q=hello" "hello param"]                                                                                                                                                                                                                             
  (println @(http/get "localhost" :query-params {:q "hello"})))   

CompilerException java.lang.IllegalArgumentException: Attempted to perform GET on unregistered URL localhost and real HTTP requests are disabled., compile:(web/db_test.clj:57:1)

感谢您的帮助。

【问题讨论】:

    标签: clojure http-kit


    【解决方案1】:

    您可以提供带有键 :url 和 :query-params 的映射,而不是字符串 :query-params

    (with-fake-http 
        [{:query-params {:q "hello"}, :url "localhost"} "hello param"]
        (println @(http/get "localhost" {:query-params {:q "hello"}})))
    

    【讨论】:

      猜你喜欢
      • 2013-08-21
      • 1970-01-01
      • 1970-01-01
      • 2010-09-17
      • 2014-01-22
      • 1970-01-01
      • 1970-01-01
      • 2015-07-09
      • 2019-07-07
      相关资源
      最近更新 更多