java.net.URISyntaxException:索引 75 处的路径中存在非法字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38122995/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.net.URISyntaxException: Illegal character in path at index 75
提问by Sachin
I'm trying to send GET request from java through Apache REST client and encountered this issue.
我正在尝试通过 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)
java.net.URISyntaxException:索引 75 处的路径中存在非法字符:http: //torrento.sharepoint.com/_api/web/getfolderbyserverrelativeurl ('/Shared Documents/test')/java.net.URI$Parser.fail 中的文件(URI.java:2848) 在 java.net.URI$Parser.checkChars(URI.java:3021) 在 java.net.URI$Parser.parseHierarchical(URI.java:3105) 在 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)
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
requestUrl 在哪里 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
我知道共享和文档之间的空间是问题所在。试图对其进行编码。但这也不起作用。请帮忙
采纳答案by Sachin
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.
我通过简单地添加获得了解决方案,requestUrl.replaceAll(" ", "%20");
但在其他特殊字符的情况下,仅此一项是行不通的。所以我们必须在发送请求之前对 url 进行编码。
Cheers :)
干杯:)