I guess the problem is in "string" function, because it tries
to get "content encoding" of stream which is not available.
In this case output stream was presumably closed by server.
So I can see two solutions:
1) always waiting until request is completed using "result" function
<code>
(ns test2
(:require [clojure.contrib.http.agent :as http]
[clojure.contrib.duck-streams :as ds]))
(let [agnt
(http/http-agent "http://www.google.com"
:method "POST"
:body "param=true")]
(http/result agnt)
(println "string: " (http/string agnt)))
(shutdown-agents)
</code>
2) applying this patch on original clojure.contrib.http.agent,
which imho solves this problem
<patch>
--- a/src/clojure/contrib/http/agent.clj
+++ b/src/clojure/contrib/http/agent.clj
@@ -263,9 +263,12 @@
headers, or clojure.contrib.duck-streams/*default-encoding* if it is
not specified."
([http-agnt]
- (string http-agnt (or (.getContentEncoding
- #^HttpURLConnection (::connection @http-agnt))
- duck/*default-encoding*)))
+ (let [a @http-agnt]
+ (if (= (::state a) ::receiving)
+ (string http-agnt (or (.getContentEncoding
+ #^HttpURLConnection (::connection @http-agnt))
+ duck/*default-encoding*))
+ (string http-agnt duck/*default-encoding*))))
([http-agnt #^String encoding]
(.toString (get-byte-buffer http-agnt) encoding)))
</patch>
HTH,
Rob