Bad Request - This combination of host and port requires TLS. with Spring Boot
I'm newbie with Spring Boot.
I'm trying to make a https call to a service, I have a Privake key to secure connection.
I hit:
http://localhost:8081/points/12345/search
I tried with https:// but I get from Postman:
Could not get any response
There was an error connecting to https://localhost:8081/points/12345/search.
From the moment I wrote
server.ssl.key-store=classpath:KeyStore.jks
server.ssl.key-store-password=test
in application.properties
, I get the error message:
Bad Request - This combination of host and port requires TLS
I have deleted all my code in my controller, I just let the endpoint so that I can invoke it.
@RestController
@SpringBootApplication
public class MainApplication {
@RequestMapping(value = "/points/{point}/search", method = RequestMethod.GET)
public PointsType getPoint(@PathVariable(value = "point") String point) {
System.out.println("hi"); // Never printed
return null;
}
public static void main(String[] args) {
SpringApplication.run(MainApplication.class, args);
}
}
Here is the file application.properties:
spring.application.name=sge
server.port=8081
server.ssl.key-store=classpath:KeyStore.jks
server.ssl.key-store-password=test
server.ssl.key-alias=homologation-staging
server.ssl.trust-store=classpath:TrustStore.jks
server.ssl.trust-store-password=test
server.ssl.client-auth=need
security.require-ssl=true
server.tomcat.remote_ip_header=x-forwarded-for
server.tomcat.protocol_header=x-forwarded-proto
What should I do ?
I used https://
at the beginning instead of http://
, it worked for me.
I got this message because I was using wrong certificate.
I misunderstood Client certificate and Server certificate.
In my case, I installed my certificate on the server, for my domain, but what I needed to do instead is to use it to make the request, as a client certificate.
you can check it how to do it here.
Client Certificate Authentication with Spring Boot
So this message is basically saying: "Hey, your SSL request is not OK", I can't find the cert file, or your cert file is not the good one, as @SerdarAtalay says, it can also significate that you didn't use https://
prefix, etc.
Hope it helps!
We can fix this by either of below listed solutions.
- Use HTTPS instead of HTTP
- Disable TLS encryption from POSTMAN setting and use HTTP
- Check application properties server.ssl.enabled= true- HTTPS , false-HTTP
- Add correct authorization credential like username and password in POSTMAN enter image description here
[1]: https://i.stack.imgur.com/vGOj9.pngenter image description here