Comments (8)
curl 'http://localhost:3001/login' \
-H 'sec-ch-ua: "Brave";v="113", "Chromium";v="113", "Not-A.Brand";v="24"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Referer: http://localhost:3333/' \
-H 'x-request-id: 6c9a49c1a540d282e01ccc81e391cab194dfa491a53cd838ed7e3bb6d1eee62e' \
-H 'sec-ch-ua-platform: "Linux"' \
--data-raw '{"username":"[email protected]","password":"hello@there","remember_me":true}' \
--compressed
This is CURL request but I'm unable to replicate the issue with Curl.
The issue is replicated when making request via JS. Here's a video for the issue.
https://www.loom.com/share/85716c7c8ad147e0b83f600780171945
from cors.
from cors.
Hi @sujit-baniya Can you provide me with the CURL request command?
from cors.
I will try to reproduce it locally.
from cors.
package main
import (
"github.com/cloudwego/hertz/pkg/app/server"
"github.com/hertz-contrib/cors"
"go.uber.org/zap"
"qiniu/cmd/api/db"
"qiniu/cmd/api/router"
"qiniu/cmd/api/rpc"
)
// biz/router/middleware/cors.go
func main() {
h := server.New(
server.WithHostPorts("0.0.0.0:8080"),
server.WithHandleMethodNotAllowed(true),
)
h.Use(cors.New(cors.Config{
AllowAllOrigins: true,
}))
logger, _ := zap.NewDevelopment()
db.Init() //redis
zap.ReplaceGlobals(logger) //日志
rpc.InitRPC() //rpc
router.Init(h) //路由
h.Spin()
}
window.onload = function demo() {
// 使用fetch API发送GET请求
fetch('http://192.168.1.109:8080/qiniu/?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTg2NjQxNDUsInBhc3N3b3JkIjoiJHBia2RmMi1zaGE1MTIkQm1uR0V1WlJRYWk5QjRzOSRiM2FhODlkMGYzM2E2MmRlZTkzZWQyMzU2NDRkM2NlYTQxODYwMTI1MzdhOTM2ODBlNWI4MDFmYmJkNjNlYWQyIiwidXNlcm5hbWUiOiJmdWNrIn0.lT3eVf-j6HA46J51T-f6WNBwkfviK7bResot96ifVMg&user_id=27', {
method: 'GET', // 请求方法
headers: {
'Access-Control-Allow-Origin': '*', // 添加CORS头部字段
},
})
.then(response => {
if (!response.ok) {
throw new Error('网络响应不是ok');
}
return response.json(); // 解析返回的JSON数据
})
.then(data => {
// 处理返回的数据
console.log(data);
})
.catch(error => {
// 处理请求中的错误
console.error('请求发生错误:', error);
});
}
路由配置:r.GET("/qiniu/publish/list", middleware.LoginMiddleware(), handler.QueryPublistList)
仍然出现
Access to fetch at 'http://192.168.1.109:8080/qiniu/ from origin 'null' has been blocked by CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response.
from cors.
@fineCoderWithLove 请给我一个能够复现问题的 demo, 你之前提供的太简略了
from cors.
from cors.
@fineCoderWithLove Can you share the code?
from cors.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cors.