Javascript Vue js axios对golang服务器的post请求,飞行前错误

Javascript Vue js axios对golang服务器的post请求,飞行前错误,javascript,go,axios,preflight,Javascript,Go,Axios,Preflight,我尝试从前端网站localhost:8888向golang后端localhost:8000发送post api请求。我得到下面列出的错误。我查看了stackoverflow,问题似乎是跨源请求和飞行前请求处理。我添加了如下所示的标题,但问题仍然存在。我希望你们能帮助我: Axios错误: OPTIONS http://localhost:8000/api/heimdall/signup 404 (Not Found) Failed to load http://localhost:8000/a

我尝试从前端网站localhost:8888向golang后端localhost:8000发送post api请求。我得到下面列出的错误。我查看了stackoverflow,问题似乎是跨源请求和飞行前请求处理。我添加了如下所示的标题,但问题仍然存在。我希望你们能帮助我:

Axios错误:

OPTIONS http://localhost:8000/api/heimdall/signup 404 (Not Found)

Failed to load http://localhost:8000/api/heimdall/signup: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8888' is therefore not allowed access. The response had HTTP status code 404.
多路复用CORS处理器

methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS"})
originsOk := handlers.AllowedOrigins([]string{"*"})
headersOk := handlers.AllowedHeaders([]string{"Accept", "Content-Type", "Content-Length", "Accept-Encoding", "X-CSRF-Token", "Authorization"})

log.Fatal(http.ListenAndServe(":8000", handlers.CORS(methodsOk, originsOk, headersOk)(r)))
Axis代码:

'use strict';

 var axios = require('axios');

function Signup(email, password) {
var apiURL = 'http://localhost:8000/api/heimdall/signup';

return new Promise((resolve, reject) => {
    axios.post(apiURL, {
        email: email,
        password: password
    })
    .then(respone => {
        console.log('Promise Signup response:', respone);
        resolve(respone);
    }, error => {
        console.log('Promise Signup error:', error);
        reject(error);
    });
});
}

export {
   Signup
};

我已经在Laravel5.5PHP中解决了这类问题

header("Access-Control-Allow-Credentials: true");
header("Access-Control-Max-Age: 1000");
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Origin, Cache-Control, Pragma, Authorization, Accept, Accept-Encoding");
header("Access-Control-Allow-Methods: PUT, POST, GET, OPTIONS, DELETE");

您可以在golang上尝试这种类型的头文件

也许您可以尝试一下,我在我的web api上使用这种类型的头文件

var handler http.Handler
{
    handler = handlers.CORS(
        handlers.AllowedOrigins([]string{"*"}),
        handlers.AllowedMethods([]string{"GET", "PUT", "PATCH", "POST", "DELETE", "OPTIONS"}),
        handlers.AllowedHeaders([]string{"Origin", "Authorization", "Content-Type"}),
        handlers.ExposedHeaders([]string{""}),
        handlers.MaxAge(10),
        handlers.AllowCredentials(),
    )(r)
    handler = handlers.RecoveryHandler(handlers.PrintRecoveryStack(true))(handler)
}
http.Handle("/", handler)
http.ListenAndServe(":8080", nil)

能否尝试在允许的标题中添加访问控制允许来源?我试过了你的两个建议,但都不起作用。飞行前仍不成功。