我使用HATEOAS作为我的REST API,它位于https后面,但链接保留在http中。在安全协议后面使用spring-HATEOAS https
"links": [
{
"rel": "self",
"href": "http://..."
},
{
"rel": "object",
"href": "..."
}
]
是否可以将HATEOAS配置为指向我的https?
我使用HATEOAS作为我的REST API,它位于https后面,但链接保留在http中。在安全协议后面使用spring-HATEOAS https
"links": [
{
"rel": "self",
"href": "http://..."
},
{
"rel": "object",
"href": "..."
}
]
是否可以将HATEOAS配置为指向我的https?
我通过specifing标题为部分解决了我的问题我的虚拟主机配置
<VirtualHost *:443>
RequestHeader set X-Forwarded-Proto "https"
ProxyPreserveHost On
ServerName www.example.com
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/server.crt
SSLCertificateKeyFile /etc/apache2/ssl/server.key
<Location/>
SSLRequireSSL
</Location>
ProxyPass/http://127.0.0.1:9000/
ProxyPassReverse/http://127.0.0.1:9000/
</VirtualHost>
这里有一种方法,通过ControllerLinkBuilder
:
Link selfLink = new Link(ControllerLinkBuilder.linkTo(methodOn(Mycontroller.class).someMethod()).toUriComponentsBuilder().scheme("https").build().toUriString(), Link.REL_SELF);
这应该产生一个Link
与自我rel和以下形式的URI:https://host:port/contextroot/pathtocontrollermethod
感谢但我该如何使用withSelfRel()和withRel()与此方法? –
如果您需要访问'UriComponentsBuilder',则认为它不可能使用这些便捷方法,但更新的答案显示手动创建'Link'无论如何。 –
这真的帮助我了!非常感谢!一个注意事项:如果你实现这个,不要忘记导入mod_headers.so模块 –