我有一个启动并运行的spring-boot应用程序,其执行器端点主要配置为/shutdown
端点。我一直使用^C
将其关闭(以前),而现在使用curl -XPOST https://address:port/shutdown
将其关闭。我的问题是如何将这样的命令映射到javascript函数,以便单击按钮即可关闭应用程序?
答案 0 :(得分:2)
无法使用javascript函数执行curl命令,因此最好使用AJAX。
请参阅以下主题。
Executing curl from Javascript?
https://stackoverflow.com/a/31179836/6572971
否则,您可以使用Java代码将其关闭,如下所示。
答案 1 :(得分:0)
通过使用提取?
const myPost = async () => {
const rawResponse = await fetch('https://address:port/shutdown', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify()
});
const response = await rawResponse.json();
console.log(response);
);