7

I'm trying to send GET request from java through Apache REST client and encountered this issue.

java.net.URISyntaxException: Illegal character in path at index 75: http://torrento.sharepoint.com/_api/web/getfolderbyserverrelativeurl('/Shared Documents/test')/files at java.net.URI$Parser.fail(URI.java:2848) at java.net.URI$Parser.checkChars(URI.java:3021) at java.net.URI$Parser.parseHierarchical(URI.java:3105) at java.net.URI$Parser.parse(URI.java:3053) at java.net.URI.(URI.java:588) at org.apache.http.client.utils.URIBuilder.(URIBuilder.java:82) at com.mstack.samples.sharepoint.SharepointApp.getAllFiles(SharepointApp.java:61) at com.mstack.samples.sharepoint.SharepointApp.main(SharepointApp.java:45)

Code snippet :-

            httpClient = HttpClientBuilder.create().build();
            uriBuilder = new URIBuilder(requestUrl);
            System.out.println(uriBuilder);
            httpGet = new HttpGet(uriBuilder.build());
            httpGet.addHeader(AUTHORIZATION, "Bearer " + TOKEN);
            httpGet.addHeader("accept", "application/json; odata=verbose");
            response = httpClient.execute(httpGet);

Where requestUrl is http://torrento.sharepoint.com/_api/web/getfolderbyserverrelativeurl('/Shared Documents/test')/files

I know the space between Shared and Documents is the issue. Tried to encode it. But that too didn't work. Please help

3
  • is: stackoverflow.com/a/724764/5655414 not what you want? Commented Jun 30, 2016 at 12:26
  • I've changed accordingly and ran into another issues. Can you say how should I change the code to get this working ? Commented Jun 30, 2016 at 12:41
  • 1
    "Tried to encode it. But that too didn't work." - Show us what you tried and what happened. Because the solution is to encode the path part of the URL ... the right way. Commented Jun 30, 2016 at 13:33

1 Answer 1

2

I've obtained the solution by simply adding requestUrl.replaceAll(" ", "%20"); But in case of other special characters this alone won't work. So we must encode url before sending request.

Cheers :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.