Three Stars

tRest using OData URL with blank space

Hello,

I have an issue using tRest component to send an OData query, with a filter like "CFISCYEAR eq 2018" in my URL because of the blank spaces.

 

My URL is like :

"https://myaccount.mysite.com/myreportQueryResults?$filter=CFISCYEAR eq 2018&$select=CFISCYEAR,CPROJECT,CPROOBJECT"

All is working fine without the red part filter=CFISCYEAR eq 2018Because of the spaces I have in this filter, I get a java.lang error : IllegalArgumentException: Illegal character in query at index XX.

 

It's not not working even after encoding the URL to UTF-8 with URLEncoder, as I get the following error : 

com.sun.jersey.api.client.ClientHandlerException: java.lang.IllegalArgumentException: URI is not absolute

 

Thanks in advance for your precious replies :=)

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
Three Stars

Re: tRest using OData URL with blank space

Thanks, I resolved it.

I replaced the blank space with %20, and it worked.

3 REPLIES
Three Stars

Re: tRest using OData URL with blank space

Thanks, I resolved it.

I replaced the blank space with %20, and it worked.

Fifteen Stars

Re: tRest using OData URL with blank space

This is combination of issues. I'll explain. First of all, you DO need to use the URLEncoder but just for certain parts. You *can* just replace those parts if you are hardcoding the URL, but URLEncoder is probably best to use. You do NOT need to encode the code in green, you DO need to encode the code in red .....

 

"https://myaccount.mysite.com/myreportQueryResults?$filter=CFISCYEAR eq 2018&$select=CFISCYEAR,CPROJECT,CPROOBJECT"

 

It is all to do with safe, reserved and unsafe characters. It is described here reasonably well (https://perishablepress.com/stop-using-unsafe-characters-in-urls/).

 

The reason you hit the second problem is that you encoded the whole thing including the https://. That is why you got the second error.

Rilhia Solutions
Fifteen Stars

Re: tRest using OData URL with blank space

That may have fixed your issue, but it is not the solution if other people hit the same problem. Your spaces were the only illegal characters in this URL. However any of these used as data would cause issues....

 

; / ? : @ = &" < > # % { } | \ ^ ~ [ ] `

Rilhia Solutions