How to pass %2f to java.net.URI without it being turned into /

1.1k Views Asked by At

I'm using Dispatch from Scala as follows:

val body = """{"count":5,"requeue":true,"encoding":"auto","truncate":50000}"""
val req = url("http://localhost:4567/api/queues/%2f/myQueue/get").as_!("guest", "guest") << (body, "application/json")

val http = new Http

val resp = http(req as_str)

The %2f gets turned into a /, so it tries to post to /api/queues///myQueue/get rather than to /api/queues/%2f/myQueue/get.

How do I escape this properly?

1

There are 1 best solutions below

2
On

% sign is used in url encoding. So, %2f gets decoded into /. try it on browser and you will see.

Use %25 to represent % sign. e.g.

val req = url("http://localhost:4567/api/queues/%252f/myQueue/get")