Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i unescape this query string

I am sending this request to a service:

get_store_data = Typhoeus::Request.new("http://localhost:3000/api/v1/store?service=#{(proxy_ticket.service)}&ticket=#{proxy_ticket.ticket}")

proxy_ticket.service resolves to this string "http://localhost:3000/api/v1/store". When the request is sent, This string is escaped to this:

service=http%3A%2F%2Flocalhost%3A3000%2Fapi%2Fv1%2Fstore

The problem is that the service on the other end expects the service parameter as "http://localhost:3000/api/v1/store" how can i prevent this query string from being escaped?

like image 359
Optimus Pette Avatar asked May 02 '14 12:05

Optimus Pette


1 Answers

The other side should be unescaping the params. If you would still like to know how to do it however here is the method uri.unescape which is used like so:

require 'uri'

enc_uri = URI.escape("http://example.com/?a=\11\15")
p enc_uri
# => "http://example.com/?a=%09%0D"

p URI.unescape(enc_uri)
# => "http://example.com/?a=\t\r"

If you ever want to quickly unescape a uri (and don't want to open a repl for some strange reason or other, like maybe it insulted your honour or something.) you can try this site

like image 195
Mike H-R Avatar answered Oct 27 '22 11:10

Mike H-R