0

I am trying to access a private API endpoint that accepts a phone number, including the country code, in the URL query parameters. Because the phone number has to include the "+", the phone number has to be encoded (i.e. the '+' becomes '%2B')

When I call this: RestClient.get("mytestserver.com/get_info?phone=%2B11231231234") in ruby, i get back an invalid response, that indicates its hitting the server, but the value isn't being read correctly.

The same call in the browser, works.

I was able to get it to work using the Net::HTTP class, by doing the following:

uri = URI("http://mytestserver.com/get_info")
uri.query = URI.encode_www_form({phone: "+11231231234"})
response = Net::HTTP.get_response(uri)

But I wanted to see if there was a way to do it via RestClient?

Hawkeye001
  • 791
  • 2
  • 11
  • 25
  • 1
    _i get back an invalid response, that indicates its hitting the server, but the value isn't being read correctly._ How do you know this? Please provide logs and an explanation for why you believe it is the + symbol that is causing the issue. – anothermh Sep 24 '20 at 23:27
  • Could you check server logs and provide details about how server is receiving request? – Shekhar Sep 25 '20 at 05:19

1 Answers1

0

It works like this.

phone = CGI.escape('+11231231234')
RestClient.get("localhost:3000/test?phone=#{phone}")

logs on server:

Started GET "/test?phone=%2B11231231234" for ::1 at 2020-09-25 11:13:13 +0100
Processing by TestersController#index as */*
  Parameters: {"phone"=>"+11231231234"}
  Rendering testers/index.html.erb within layouts/application