Hello All, I am trying to add some functionality to http-client. Basically, I need the ability to do get requests on a server while ignoring ssl errors. Once I figure out how to get it working, I'll put it up on github and people can pull it if they'd like.
I am working from a fork of http-client that has support for cookies, located here: https://github.com/r0man/clj-http/commits/cookies I used r0man's changes ( https://github.com/r0man/clj-http/commit/f8152c6182c148539148fdc7f77faab14b7567c3) as an example of what I needed to change in order to add "ssl error ignore" capability. I used some java wisdom from stackoverflow ( http://stackoverflow.com/questions/2012497/accepting-a-certificate-for-https-on-android/3904473#3904473) to ignore ssl errors. I came up with this: src/http-client/client.clj ... (:use [clj-http.cookies :only (wrap-cookies)] [clj-http.noauth :only (wrap-noauth)]))) ... and ... (defn wrap-request "Returns a battaries-included HTTP request function coresponding to the given core client. See client/client." [request] (-> request wrap-noauth wrap-redirects wrap-exceptions ... I put wrap-noauth (which might have been a bad name) at the beginning because it takes the old client and actually returns a new one: src/http-client/noauth.clj (ns clj-http.noauth "Allows client to ignore some SSL errors (only use in dev!)" (:import (javax.net.ssl HostnameVerifier HttpsURLConnection)) (:import (org.apache.http.conn.ssl SSLSocketFactory X509HostnameVerifier)) (:import (org.apache.http.conn.scheme Scheme SchemeRegistry)) (:import (org.apache.http.impl.client DefaultHttpClient)) (:import (org.apache.http.impl.conn SingleClientConnManager))) (defn wrap-noauth [client] (fn [req] (if (:noauth req) (let [registry (SchemeRegistry.) hostname-verifier SSLSocketFactory/ALLOW_ALL_HOSTNAME_VERIFIER socket-factory (SSLSocketFactory/getSocketFactory) _ (.setHostnameVerifier socket-factory hostname-verifier) _ (.register registry (Scheme. "https" socket-factory 443)) noauth-client (DefaultHttpClient. (SingleClientConnManager. (.getParams client) registry) (.getParams client)) _ (HttpsURLConnection/setDefaultHostnameVerifier hostname-verifier)] (noauth-client req)) (client req)))) I essentially modeled wrap-noauth on the stackoverflow thread. When I run (c/get my-url {:noauth true :cookies ... I get: user=> IllegalArgumentException No matching field found: getParams for class clojure.lang.Var clojure.lang.Reflector.getInstanceField (Reflector.java:289) Taking the ':noauth true' out of the argument map makes the error go away. The only place I see getParams used is towards the beginning of the request function in core.clj src/http-client/core.clj ... (let [http-client (DefaultHttpClient.)] (try (-> http-client (.getParams) (.setParameter ClientPNames/COOKIE_POLICY CookiePolicy/BROWSER_COMPATIBILITY)) (let [http-url (str scheme "://" server-name ... I'm still not sure what is going on... Am I breaking it by instantiating a new DefaultHttpClient? Should a new key for noauth be put in the parameters to core/request [{:keys [noauth... the cookies branch didn't do this, so I wasn't sure. Thanks in advance for the help. Hopefully, once this is figured out, it will be useful to others as well. John -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en