I am new to the Spring Boot, but I have worked with Java before on HTTP OPTIONS command.
I am building a service method that takes in an URL and test that URL using HTTP OPTIONS command.
Below is what I have written using Java:
import java.net.HttpURLConnection;
import java.net.URL;
...
public String testConnection(URL url) {
try {
String type = "text/plain;charset=UTF-8";
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("OPTIONS");
conn.setRequestProperty("Content-Type", type);
System.out.println(String.format("HTTP %d: %s",
conn.getResponseCode(), conn.getResponseMessage()));
for(String header : conn.getHeaderFields().keySet() ){
System.out.println(String.format("%s : %s",
header, conn.getHeaderFields().get(header)));
}
String rMessage = conn.getResponseMessage();
System.out.println ("Response " + rMessage);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Is there a Spring Boot equivalent way of implementing the HTTP OPTIONS request? If so, could I also add credentials (username and password) to the header as part of the request? Thanks.