.uri(URI.create(ipp))
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response2 = HttpClient.newHttpClient().send(request2, HttpResponse.BodyHandlers.ofString());
System.out.println(response2.body());```
compiled but throwing this error
```Caused by: java.net.URISyntaxException: Illegal character in authority at index 8:```
#HttpRequest passing variable to URI create error
21 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @bright dagger! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
what is in ipp
a variable
:slow_clap:
import java.util.*;
import java.net.http.*;
import java.net.URI ;
class test {
public static void main(String[] a)
throws Throwable
{
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("url1"))
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
//System.out.println(response.body());
String ipp = response.body().toString();
//System.out.println("success");
//System.out.println(ipp.toString());
//ipp = "anyurl";
HttpRequest request2 = HttpRequest.newBuilder()
.uri(URI.create(ipp))
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response2 = HttpClient.newHttpClient().send(request2, HttpResponse.BodyHandlers.ofString());
System.out.println(response2.body());
}
}```
can you paste value of ipp the exception states that it has an illegal character
/run ```java
import java.net.URI ;
URI.create("u rl$1");
@zealous token I only received java(15.0.2) error output
Exception in thread "main" java.lang.IllegalArgumentException: Illegal character in path at index 1: u rl$1
at java.base/java.net.URI.create(URI.java:906)
at temp.main(file0.code.java:3)
Caused by: java.net.URISyntaxException: Illegal character in path at index 1: u rl$1
at java.base/java.net.URI$Parser.fail(URI.java:2963)
at java.base/java.net.URI$Parser.checkChars(URI.java:3134)
at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3216)
at java.base/java.net.URI$Parser.parse(URI.java:3175)
at java.base/java.net.URI.<init>(URI.java:623)
at java.base/java.net.URI.create(URI.java:904)
at temp.main(file0.code.java:3)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at jdk.compiler/com.sun.tools.javac.launcher.Main.execute(Main.java:415)
i get the upper half http response when dry runned without second half
but the second http request is causing error
see if i add space(illegal character) it throws an error
yeah because it has illegal characters in it just print the value and see if its valid url
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
String ipp = response.body().toString();
ipp = ipp.replaceAll("\s", "");
this helpexd