这是我的第一个帖子.
我刚刚开始学习围棋和角棋,我正在try 将角棋应用程序连接到围棋API.这两个我都写过了,我不得不找出问题的根源.我认为这是CORS问题,但是如果我不在我的Angular http请求中包括头代码行,它就可以正常工作.在这一点上,我只想添加标题.授权码尚未实现.
这两个应用程序都在本地运行,Go应用程序在端口5000上运行,ANGING应用程序在4200上运行
不起作用的Angular http请求:
this.http.get<ProjectedBalance>(requestUrl, {headers: new HttpHeaders().set('Authorization', 'my-auth-token')})
.subscribe(data => {
this.projBalance = data.projBalance;
}
有效的http请求:
this.http.get<ProjectedBalance>(requestUrl)
.subscribe(data => {
this.projBalance = data.projBalance;
}
我收到这个错误:
对飞行前请求的响应未通过访问控制判断:否
我在我的围棋代码中使用了Gorilla/MUX和Gorilla/Handler
router := mux.NewRouter()
router.HandleFunc("/home/{endDate}", GetProjBalance).Methods("GET", "OPTIONS")
headersOk := handlers.AllowedHeaders([]string{"X-Requested-With, Content-Type, Authorization"})
originsOk := handlers.AllowedOrigins([]string{"*"})
methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS"})
//start server on port
log.Fatal(http.ListenAndServe(":5000", handlers.CORS(originsOk, headersOk, methodsOk)(router)))
来自Chrome Dev工具的标题
Request URL:http://localhost:5000/home/2020-12-21
Request Method:OPTIONS
Status Code:403 Forbidden
Remote Address:[::1]:5000
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
Content-Length:0
Content-Type:text/plain; charset=utf-8
Date:Mon, 20 Nov 2017 21:39:43 GMT
Request Headers
view source
Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.9,uz;q=0.8
Access-Control-Request-Headers:authorization
Access-Control-Request-Method:GET
Connection:keep-alive
Host:localhost:5000
Origin:http://localhost:4200