Fork me on GitHub
#clj-http
<
2024-01-25
>
kokonut14:01:57

hi I am trying to make a get request like the following in clj-http.


  ?input=%2B16502530000
  &inputtype=phonenumber
When I use cUrl, it works well like below
curl -L -X GET ''
But I am not going through with my clojure code using clj-http.
(client/get
 "" ;; removed slash at the end
 {:query-params
  {:input "%2B16502530000"
   :inputtype "phonenumber"}})
Can someone enlighten me what I am doing wrong?

mmer15:01:44

Have tried without the slash at the end of the url.

mmer15:01:02

;; Query parameters
(client/get "" {:query-params {"q" "foo, bar"}})

kokonut15:01:52

yes I just tried without the slash. It reaches and gets 200 but google map says my query is invalid.

kokonut15:01:11

It is interesting because my curl request doesn't get this complaint.

mmer15:01:07

Have you tried

(client/get
 "" ;; removed slash at the end
 {:query-params
  {"input" "%2B16502530000"
   "inputtype" "phonenumber"}})

kokonut15:01:35

yes, I just did and got the same complaint.

mmer15:01:05

Sorry, I wonder if there is some header value you need to set?

kokonut15:01:08

Don't be. It's a headache. But I just did put all params in the url string like curl

(client/get 
"")
and it works! I know it looks primitive but it's important that it works. 🙂

mmer15:01:20

Maybe try this:

;; save the request that was sent in a :request key in the response:
(client/get "" {:save-request? true})

mmer15:01:28

To see what you sent.

kokonut15:01:57

that must be helpful. let me try

mmer15:01:18

There are different debug modes.

kokonut15:01:45

Ah I found the cause

👍 1
kokonut15:01:26

the library was changing the input value like this

%252B16502530000
what I meant was
%2B16502530000

kokonut15:01:13

Probably it is because of %?

mmer15:01:10

Is this because normally the % is followed by 2 characters or something like that.

mmer15:01:19

I had wondered if the % was causing the issue - maybe encoding it for a url would help?

mmer15:01:32

Should that be a "+"

mmer15:01:51

i.e. %2B = +

kokonut15:01:01

Problem solved. That was it!

👍 1
kokonut15:01:23

I am getting these data successfully

;;     :body
;;     "{\n   \"candidates\" : \n   [\n      {\n         \"place_id\" : \"ChIJj61dQgK6j4AR4GeTYWZsKWw\"\n      },\n      {\n         \"place_id\" : \"ChIJ2Xz75-t5j4ARB2DdjJy2uqA\"\n      },\n      {\n         \"place_id\" : \"ChIJC_TKnI84K4gR7PNbCsldD0c\"\n      },\n      {\n         \"place_id\" : \"ChIJyesLCqa3j4ARxZkBe9Qt_mk\"\n      },\n      {\n         \"place_id\" : \"ChIJhbgMV7dhK4gR33wqaPHOCuQ\"\n      },\n      {\n         \"place_id\" :

kokonut15:01:35

Thanks so much for your help @U4C3ZU6KX