[clj-http] POST Request Issues

699 views
Skip to first unread message

Akash Kothawale

unread,
Sep 13, 2013, 8:56:44 AM9/13/13
to clj-...@googlegroups.com

I am trying to write a clojure equivalent of the following python code.

requests.post(url, auth=(username, passwd), data=information)

This is what I came up with.

(client/post url {:basic-auth [username passwd] :form-params information})]

When I try running these with url http://requestb.in/ (A site to test Http Requests) I get the similar information. However, when I try to run the same section of code for an API service, I get 200 with python, but a 400 with clojure.

If I try that with :body information then I get an Exceptionclojure.lang.PersistentArrayMap cannot be cast to [B

What is could possibly be wrong here?

Thanks,

Akash

kiran kulkarni

unread,
Sep 13, 2013, 5:00:13 PM9/13/13
to clj-...@googlegroups.com
Hello Akash,

You have to use :form-params information and :body information will not work because body needs a "byte-array"
The information that you have provided is not enough to debug this problem. 

I tried to use http://requestb.in/, it doesn't return anything apart from "Ok". IMO this is not comprehensive.
You should try http://httpbin.org/post it returns you JSON of the whole request it received. Try it from Python and Clojure both and compare the responses.

e.g.
$ curl -v -X POST -d "fizz=buzz" http://httpbin.org/post
* About to connect() to httpbin.org port 80 (#0)
*   Trying 54.225.138.124...
* connected
* Connected to httpbin.org (54.225.138.124) port 80 (#0)
> POST /post HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5
> Host: httpbin.org
> Accept: */*
> Content-Length: 9
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 9 out of 9 bytes
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Content-Type: application/json
< Date: Fri, 13 Sep 2013 20:54:28 GMT
< Server: gunicorn/0.17.4
< Content-Length: 440
< Connection: keep-alive
<
{
  "data": "",
  "files": {},
  "headers": {
    "User-Agent": "curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5",
    "Connection": "close",
    "Content-Length": "9",
    "Host": "httpbin.org",
    "Accept": "*/*",
    "Content-Type": "application/x-www-form-urlencoded"
  },
  "json": null,
  "args": {},
  "origin": "122.170.27.53",
  "form": {
    "fizz": "buzz"
  }
* Connection #0 to host httpbin.org left intact
}* Closing connection #0

Kiran Kulkarni


--
You received this message because you are subscribed to the Google Groups "Clojure Users Group Pune" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clj-pune+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/clj-pune.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages