1

我怎样才能with-fake-http拦截http/get包含:query-params. 以下代码产生异常

 (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: 尝试在未注册的 URL localhost 上执行 GET,并且禁用了真正的 HTTP 请求。,编译:(web/db_test.clj:57:1)

谢谢你的帮助。

4

1 回答 1

2

代替 String "localhost?q=hello",您可以提供带有键的地图:url:query-params

(with-fake-http 
    [{:query-params {:q "hello"}, :url "localhost"} "hello param"]
    (println @(http/get "localhost" {:query-params {:q "hello"}})))
于 2017-03-31T07:21:04.150 回答