Re: Problems with URL params and http-agent
On 18 June 2010 23:54, Timothy Washington twash...@gmail.com wrote: That works, thanks. It's a bit weird because I did try just http encoding the parameters before. But I obviously encoded the wrong characters, or maybe used the wrong character encoding. Hmmm. Thanks :) No problem :) -- Michael Wood esiot...@gmail.com -- 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
Re: Problems with URL params and http-agent
Hmm, this is a good idea and I got the GET request string as... */exist/rest/rootDir/system.main.system/aauthentication.main.authentication/users.aauth.users/user.one/user.one?_wrap=no_query=declare default element namespace 'com/interrupt/bookkeeping/users';//user[ @id='one']* This exact URI (behind http://localhost:8080) works when used by the browser, or wget. The service is a RESTful interface around the eXist XML DB. And I'm suspecting the DB is returning the correct result, I'm just not handling it somehow in clojure. I though my code was pretty straight forward (carbon copy of Stuart Halloway's handler). (clojure.contrib.http.agent/result (clojure.contrib.http.agent/http-agent http://localhost:6300/exist/rest/rootDir/system.main.system/aauthentication.main.authentication/users.aauth.users/user.one/user.one?_wrap=no_query=declaredefault element namespace 'com/interrupt/bookkeeping/users';//user[ @id='one'] :method GET :header {Content-Type text/xml} :handler (fn [agnt] (with-open [w (clojure.contrib.io/writer /tmp/out)] (clojure.contrib.io/copy (clojure.contrib.http.agent/stream agnt) w)) ) ) ) Hmmm Tim On Thu, Jun 17, 2010 at 2:26 PM, Jim Blomo j...@xcf.berkeley.edu wrote: On Wed, Jun 16, 2010 at 6:21 PM, Timothy Washington twash...@gmail.com wrote: Hey all, something very weird happens when trying to use the http-agent. If I execute a) or b) in a browser, I get the desired result XML. a) http://RESTful/path/to/xml b) http://RESTful/path/to/xml?_wrap=no_query=declare default element namespace 'com/interrupt/bookkeeping/users';//user[ @id='one'] It's hard to say without the specific error you're seeing and what service you're hitting, but one technique I've used for debugging HTTP calls is to setup netcat on another port. Then make the same requests with the browser and library to the new port and compare netcat's output. Perhaps they are escaping the paths differently. Cheers, Jim -- 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.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- 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
Re: Problems with URL params and http-agent
Oh... and the /tmp/out file is empty. Tim On Fri, Jun 18, 2010 at 8:53 AM, Timothy Washington twash...@gmail.comwrote: Hmm, this is a good idea and I got the GET request string as... */exist/rest/rootDir/system.main.system/aauthentication.main.authentication/users.aauth.users/user.one/user.one?_wrap=no_query=declare default element namespace 'com/interrupt/bookkeeping/users';//user[ @id='one']* This exact URI (behind http://localhost:8080) works when used by the browser, or wget. The service is a RESTful interface around the eXist XML DB. And I'm suspecting the DB is returning the correct result, I'm just not handling it somehow in clojure. I though my code was pretty straight forward (carbon copy of Stuart Halloway's handler). (clojure.contrib.http.agent/result (clojure.contrib.http.agent/http-agent http://localhost:6300/exist/rest/rootDir/system.main.system/aauthentication.main.authentication/users.aauth.users/user.one/user.one?_wrap=no_query=declaredefault element namespace 'com/interrupt/bookkeeping/users';//user[ @id='one'] :method GET :header {Content-Type text/xml} :handler (fn [agnt] (with-open [w (clojure.contrib.io/writer /tmp/out)] (clojure.contrib.io/copy (clojure.contrib.http.agent/stream agnt) w)) ) ) ) Hmmm Tim On Thu, Jun 17, 2010 at 2:26 PM, Jim Blomo j...@xcf.berkeley.edu wrote: On Wed, Jun 16, 2010 at 6:21 PM, Timothy Washington twash...@gmail.com wrote: Hey all, something very weird happens when trying to use the http-agent. If I execute a) or b) in a browser, I get the desired result XML. a) http://RESTful/path/to/xml b) http://RESTful/path/to/xml?_wrap=no_query=declare default element namespace 'com/interrupt/bookkeeping/users';//user[ @id='one'] It's hard to say without the specific error you're seeing and what service you're hitting, but one technique I've used for debugging HTTP calls is to setup netcat on another port. Then make the same requests with the browser and library to the new port and compare netcat's output. Perhaps they are escaping the paths differently. Cheers, Jim -- 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.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- 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
Re: Problems with URL params and http-agent
That's a good idea which I tried. But no dice. I have a feeling I'm not handling the response properly in Clojure. See my other posts here. Tim On Thu, Jun 17, 2010 at 3:57 PM, RandyHudson randy_hud...@mac.com wrote: You don't want to encode the whole URL, just the keys and values in the query string. Something like this: (defn encode-params [request-params] (let [encode #(URLEncoder/encode (str %) UTF-8) coded (for [[n v] request-params] (str (encode n) = (encode v)))] (apply str (interpose coded On Jun 16, 9:21 pm, Timothy Washington twash...@gmail.com wrote: Hey all, something very weird happens when trying to use the http-agent. If I execute a) or b) in a browser, I get the desired result XML. a)http://RESTful/path/to/xml b)http://RESTful/path/to/xml?_wrap=no_query=declaredefault element namespace 'com/interrupt/bookkeeping/users';//user[ @id='one'] However, using clojure, If I try the same call, d) in this case will NOT work. c) (clojure.contrib.http.agent/http-agent http://RESTful/path/to/xml;) ; works d) (clojure.contrib.http.agent/http-agent http://RESTful/path/to/xml?_wrap=no_query=declaredefault element namespace 'com/interrupt/bookkeeping/users';//user[ @id='one']) ; doesn't work I've tried url-encoding the url using the below function, but that doesn't help either. (defn url-encode [text] (URLEncoder/encode text UTF-8)) Is the something obvious I'm missing? Thanks -- 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.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- 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
Re: Problems with URL params and http-agent
On 18 June 2010 14:53, Timothy Washington twash...@gmail.com wrote: Hmm, this is a good idea and I got the GET request string as... /exist/rest/rootDir/system.main.system/aauthentication.main.authentication/users.aauth.users/user.one/user.one?_wrap=no_query=declare default element namespace 'com/interrupt/bookkeeping/users';//user[ @id='one'] This exact URI (behind http://localhost:8080) works when used by the browser, or wget.[...] But spaces etc. are not valid as part of a URI. They need to be escaped. What happens if you try this hard-coded URL: http://localhost:8080/exist/rest/rootDir/system.main.system/aauthentication.main.authentication/users.aauth.users/user.one/user.one?_wrap=no_query=declare%20default%20element%20namespace%20%27com/interrupt/bookkeeping/users%27%3B//user%5B%40id%3D%27one%27%5D Try that in the browser, wget and also your Clojure program. It might also help to get a simple CGI script or something that can extract the _wrap and _query parameters from the query string and just print or log them so you can compare what you get from the browser and wget and your program. -- Michael Wood esiot...@gmail.com -- 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
Re: Problems with URL params and http-agent
On Wed, Jun 16, 2010 at 6:21 PM, Timothy Washington twash...@gmail.com wrote: Hey all, something very weird happens when trying to use the http-agent. If I execute a) or b) in a browser, I get the desired result XML. a) http://RESTful/path/to/xml b) http://RESTful/path/to/xml?_wrap=no_query=declare default element namespace 'com/interrupt/bookkeeping/users';//user[ @id='one'] It's hard to say without the specific error you're seeing and what service you're hitting, but one technique I've used for debugging HTTP calls is to setup netcat on another port. Then make the same requests with the browser and library to the new port and compare netcat's output. Perhaps they are escaping the paths differently. Cheers, Jim -- 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
Re: Problems with URL params and http-agent
You don't want to encode the whole URL, just the keys and values in the query string. Something like this: (defn encode-params [request-params] (let [encode #(URLEncoder/encode (str %) UTF-8) coded (for [[n v] request-params] (str (encode n) = (encode v)))] (apply str (interpose coded On Jun 16, 9:21 pm, Timothy Washington twash...@gmail.com wrote: Hey all, something very weird happens when trying to use the http-agent. If I execute a) or b) in a browser, I get the desired result XML. a)http://RESTful/path/to/xml b)http://RESTful/path/to/xml?_wrap=no_query=declaredefault element namespace 'com/interrupt/bookkeeping/users';//user[ @id='one'] However, using clojure, If I try the same call, d) in this case will NOT work. c) (clojure.contrib.http.agent/http-agent http://RESTful/path/to/xml;) ; works d) (clojure.contrib.http.agent/http-agent http://RESTful/path/to/xml?_wrap=no_query=declaredefault element namespace 'com/interrupt/bookkeeping/users';//user[ @id='one']) ; doesn't work I've tried url-encoding the url using the below function, but that doesn't help either. (defn url-encode [text] (URLEncoder/encode text UTF-8)) Is the something obvious I'm missing? Thanks -- 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
Problems with URL params and http-agent
Hey all, something very weird happens when trying to use the http-agent. If I execute a) or b) in a browser, I get the desired result XML. a) http://RESTful/path/to/xml b) http://RESTful/path/to/xml?_wrap=no_query=declare default element namespace 'com/interrupt/bookkeeping/users';//user[ @id='one'] However, using clojure, If I try the same call, d) in this case will NOT work. c) (clojure.contrib.http.agent/http-agent http://RESTful/path/to/xml;) ; works d) (clojure.contrib.http.agent/http-agent http://RESTful/path/to/xml?_wrap=no_query=declare default element namespace 'com/interrupt/bookkeeping/users';//user[ @id='one']) ; doesn't work I've tried url-encoding the url using the below function, but that doesn't help either. (defn url-encode [text] (URLEncoder/encode text UTF-8)) Is the something obvious I'm missing? Thanks -- 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