Skip to content

Instantly share code, notes, and snippets.

@Kungi
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kungi/4008221dc26b60225a25 to your computer and use it in GitHub Desktop.
Save Kungi/4008221dc26b60225a25 to your computer and use it in GitHub Desktop.
error during clj-http/post
(let [my-cs (clj-http.cookies/cookie-store)]
(http/post (str (url) "/login") {:params {:username "login"
:password "pass"}
:form-params {:username "login"
:password "pass"}
:cookie-store my-cs})
(let [csrftoken (url-decode (get-in (clj-http.cookies/get-cookies my-cs) ["csrftoken" :value]))]
(http/post (str (url) "/action/infocenter/1/upload-offer")
{:multipart [{:name "__anti-forgery-token" :content csrftoken}
{:name "customer-id" :content "2342-does-not-matter"}
{:name "file" :content (clojure.java.io/file
(str "test-data/test.pdf"))}]
:cookie-store my-cs})))
(let [my-cs (clj-http.cookies/cookie-store)
customer-id (create-customer)
test-filename "test.pdf"]
(http/post (str (url) "/login") {:params {:username "login"
:password "pass"}
:form-params {:username "login"
:password "pass"}
:cookie-store my-cs})
(let [csrftoken (url-decode (get-in (clj-http.cookies/get-cookies my-cs) ["csrftoken" :value]))]
(http/post (str (url) "/action/infocenter/1/upload-offer")
{:multipart [{:name "__anti-forgery-token" :content csrftoken}
{:name "customer-id" :content customer-id}
{:name "file"
:content (clojure.java.io/file
(str "test-data/" test-filename))}]
;; java.lang.ClassCastException: org.apache.http.client.methods.HttpGet cannot be cast to org.apache.http.HttpEntityEnclosingRequest in the line above
:cookie-store my-cs}))
(let [test-filename "test.pdf"
offers (db/get-offers-for-customer-on-infocenter global/*db* customer-id 1)
offer-id (:offer_id (first (filter #(.startsWith (:filename %) test-filename) offers)))]
(http/get (str (url) "/action/infocenter/1/show-offer/" offer-id
"/customer/" customer-id
"/filename/test.pdf")
{:cookie-store my-cs})
(db/delete-offer-for-customer global/*db* 1 customer-id offer-id)))
@Kungi
Copy link
Author

Kungi commented Nov 21, 2014

actual: java.lang.ClassCastException: org.apache.http.client.methods.HttpGet cannot be cast to org.apache.http.HttpEntityEnclosingReq
uest
at clj_http.core$request.invoke (core.clj:272)
clojure.lang.Var.invoke (Var.java:379)
clj_http.client$wrap_request_timing$fn__15640.invoke (client.clj:751)
clj_http.headers$wrap_header_map$fn__14403.invoke (headers.clj:136)
clj_http.client$wrap_query_params$fn__15544.invoke (client.clj:578)
clj_http.client$wrap_basic_auth$fn__15551.invoke (client.clj:594)
clj_http.client$wrap_oauth$fn__15555.invoke (client.clj:604)
clj_http.client$wrap_user_info$fn__15560.invoke (client.clj:617)
clj_http.client$wrap_url$fn__15626.invoke (client.clj:717)
clj_http.client$wrap_redirects$fn__15342.invoke (client.clj:212)
clj_http.client$follow_redirect.invoke (client.clj:187)
clj_http.client$wrap_redirects$fn__15342.invoke (client.clj:228)
clj_http.client$wrap_decompression$fn__15370.invoke (client.clj:284)
clj_http.client$wrap_input_coercion$fn__15488.invoke (client.clj:445)
clj_http.client$wrap_additional_header_parsing$fn__15509.invoke (client.clj:494)
clj_http.client$wrap_output_coercion$fn__15479.invoke (client.clj:398)
clj_http.client$wrap_exceptions$fn__15322.invoke (client.clj:164)
clj_http.client$wrap_accept$fn__15519.invoke (client.clj:522)
clj_http.client$wrap_accept_encoding$fn__15525.invoke (client.clj:536)
clj_http.client$wrap_content_type$fn__15514.invoke (client.clj:512)
clj_http.client$wrap_form_params$fn__15605.invoke (client.clj:683)
clj_http.client$wrap_nested_params$fn__15622.invoke (client.clj:707)
clj_http.client$wrap_method$fn__15565.invoke (client.clj:624)
clj_http.cookies$wrap_cookies$fn__14322.invoke (cookies.clj:121)
clj_http.links$wrap_links$fn__14598.invoke (links.clj:50)
clj_http.client$wrap_unknown_host$fn__15630.invoke (client.clj:726)
clj_http.client$post.doInvoke (client.clj:841)
clojure.lang.RestFn.invoke (RestFn.java:423)
clj_demgen.demgen_test/fn (demgen_test.clj:344)
clojure.test$test_var$fn__7187.invoke (test.clj:704)
clojure.test$test_var.invoke (test.clj:704)
clojure.test$test_vars$fn__7209$fn__7214.invoke (test.clj:722)
clojure.test$default_fixture.invoke (test.clj:674)
clojure.test$test_vars$fn__7209.invoke (test.clj:722)
clj_demgen.demgen_test$run_in_firefox.invoke (demgen_test.clj:40)
clojure.test$compose_fixtures$fn__7181$fn__7182.invoke (test.clj:681)
clj_demgen.test_data$with_test_data.invoke (test_data.clj:205)
clojure.test$compose_fixtures$fn__7181$fn__7182.invoke (test.clj:681)
clj_demgen.test_data$with_test_home_folder.invoke (test_data.clj:31)
clojure.test$compose_fixtures$fn__7181$fn__7182.invoke (test.clj:681)
clj_demgen.demgen_test$with_test_system.invoke (demgen_test.clj:30)
clojure.test$compose_fixtures$fn__7181$fn__7182.invoke (test.clj:681)
clojure.test$default_fixture.invoke (test.clj:674)
clojure.test$compose_fixtures$fn__7181.invoke (test.clj:681)
clojure.test$compose_fixtures$fn__7181.invoke (test.clj:681)
clojure.test$compose_fixtures$fn__7181.invoke (test.clj:681)
clojure.test$compose_fixtures$fn__7181.invoke (test.clj:681)
clojure.test$test_vars.invoke (test.clj:718)
clojure.test$test_all_vars.invoke (test.clj:728)
clojure.test$test_ns.invoke (test.clj:747)
clojure.core$map$fn__4245.invoke (core.clj:2559)
clojure.lang.LazySeq.sval (LazySeq.java:40)
clojure.lang.LazySeq.seq (LazySeq.java:49)
clojure.lang.Cons.next (Cons.java:39)
clojure.lang.RT.boundedLength (RT.java:1654)
clojure.lang.RestFn.applyTo (RestFn.java:130)
clojure.core$apply.invoke (core.clj:626)
clojure.test$run_tests.doInvoke (test.clj:762)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.core$apply.invoke (core.clj:624)
user$eval26128$fn__26243$fn__26294.invoke (form-init3118969655368686674.clj:1)
user$eval26128$fn__26243$fn__26244.invoke (form-init3118969655368686674.clj:1)
user$eval26128$fn__26243.invoke (form-init3118969655368686674.clj:1)
user$eval26128.invoke (form-init3118969655368686674.clj:1)
clojure.lang.Compiler.eval (Compiler.java:6703)
clojure.lang.Compiler.eval (Compiler.java:6693)
clojure.lang.Compiler.load (Compiler.java:7130)
clojure.lang.Compiler.loadFile (Compiler.java:7086)
clojure.main$load_script.invoke (main.clj:274)
clojure.main$init_opt.invoke (main.clj:279)
clojure.main$initialize.invoke (main.clj:307)
clojure.main$null_opt.invoke (main.clj:342)
clojure.main$main.doInvoke (main.clj:420)
clojure.lang.RestFn.invoke (RestFn.java:421)
clojure.lang.Var.invoke (Var.java:383)
clojure.lang.AFn.applyToHelper (AFn.java:156)
clojure.lang.Var.applyTo (Var.java:700)
clojure.main.main (main.java:37)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment