我试图通过 Apache REST 客户端从 java 发送 GET 请求并遇到了这个问题。
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)
代码片段:-
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
我知道 Shared 和 Documents 之间的空间是问题所在。试图对其进行编码。但这也没有用。请帮忙
最佳答案
我通过简单地添加 requestUrl.replaceAll("", "%20");
获得了解决方案
但如果是其他特殊字符,仅此一项是行不通的。所以我们必须在发送请求之前对url进行编码。
干杯:)
关于java.net.URISyntaxException : Illegal character in path at index 75,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38122995/