此问题通常是由于AEM系统未授权或已过期引起的。要解决此问题,需要在AEM系统中设置CORS(跨域资源共享),以便在Axios请求中包含凭据。
以下是解决方案的代码示例:
axios({
method: 'POST',
url: 'https://example.com/path/to/servlet',
withCredentials: true,
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
},
data: {
// request data
},
}).then((response) => {
// handle response
}).catch((error) => {
// handle error
});
在这个示例中,withCredentials参数被设置为true,以便在Axios请求中包含凭据。同时,设置了CORS头,以便正确授权请求。
确保在AEM系统中正确设置CORS,并根据需要调整Axios请求的参数,以匹配您的设置。