Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript axios向后端发送POST请求时出现CORS错误_Javascript_Http_Cors_Axios - Fatal编程技术网

Javascript axios向后端发送POST请求时出现CORS错误

Javascript axios向后端发送POST请求时出现CORS错误,javascript,http,cors,axios,Javascript,Http,Cors,Axios,我使用AJAX将登录请求发送到后端。但是我试着用axios做同样的事情,但是得到了cors错误。 这是我的要求 CORS响应已在后端中设置 .post('https://testconsole.pva.com/j_spring_security_check', { data: { j_username: email, j_password: password }, withCredentials:

我使用AJAX将登录请求发送到后端。但是我试着用axios做同样的事情,但是得到了cors错误。 这是我的要求

CORS响应已在后端中设置

      .post('https://testconsole.pva.com/j_spring_security_check', {
        data: {
          j_username: email,
          j_password: password
        },
        withCredentials: true,
        crossorigin: true,
        headers: {

          'Content-Type': 'application/x-www-form-urlencoded',
          'Accept': 'application/json',
          'Access-Control-Request-Method': 'POST',
          'Access-Control-Request-Headers': 'X-PINGOTHER, Content-Type'
        }

      })




const api = axios.create({
  baseUrl: “https://testconsole.pva.com”,
  headers: {
    common: {  
          'Content-Type': 'application/json',
          'Accept': 'application/json',
          'WithCredentials': true,
          'Access-Control-Allow-Origin': '*'
});
....
const myRequest = await api({
  method: 'post',
  url: '/j_spring_security_check',
  data: JSON.stringify({
          j_username: email,
          j_password: password
        })
});