Replace only the host and port numbers that are part of the URL in java. Here's how to use spring's UriComponentsBuilder
.
Almost a copy of https://stackoverflow.com/questions/46667342/java-replace-host-in-url. Specify the original URL in UriComponentsBuilder
and then replace it with a method such as `` `host```.
import org.springframework.web.util.UriComponentsBuilder;
String url = "http://localhost:8080/example?param=hoge";
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
String url2 = builder.host("hoge-host").toUriString();
System.out.println(url2);// http://hoge-host:8080/example?param=hoge
UriComponentsBuilder
.Recommended Posts