今天用go写接口的时候,提示跨域相关错误:
"Failed to fetch.
Possible Reasons:
CORS
Network Failure
URL scheme must be "http" or "https" for CORS request."
结合AI多次排查代码后,发现跨域配置没有问题,其他接口调用也不会出现跨域问题。
这里记录一下导致的原因,与跨域设置无关,是在接口中接收解析参数的代码字段没有没有对应上。
有问题的代码
go
type requestData struct {
workRadius float32 `json:"workRadius"`
}
修改后,没问题的代码
go
type requestData struct {
WorkRadius float32 `json:"workRadius"`
}
就是"WorkRadius",大小写导致的,但是不明白为什么提示的跨域相关的错误。