java.net.URISyntaxException:索引75

时间:2016-06-30 12:23:31

标签: java rest sharepoint apache-httpclient-4.x

我试图通过Apache REST客户端从java发送GET请求并遇到了这个问题。

  

java.net.URISyntaxException:索引75处路径中的非法字符:   http://torrento.sharepoint.com/_api/web/getfolderbyserverrelativeurl(' /共享   java.net.URI上的文档/测试')/文件$ Parser.fail(URI.java:2848)     在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)     在   com.mstack.samples.sharepoint.SharepointApp.main(SharepointApp.java:45)

代码段: -

            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);

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

的位置

我知道共享和文档之间的空间是个问题。试图编码。但那也没有用。请帮忙

1 个答案:

答案 0 :(得分:1)

我只需添加requestUrl.replaceAll(" ", "%20");即可获得解决方案 但是在其他特殊角色的情况下,这一切都无法奏效。所以我们必须在发送请求之前对url进行编码。

干杯:)