我有一个用 Go Gin 编写的简单服务器:package mainimport ( "net/http" "github.com/gin-contrib/cors" "github.com/gin-gonic/gin")func main() { router := gin.Default() router.Use(cors.Default()) router.GET("/", func(context *gin.Context) { context.JSON(http.StatusOK, gin.H{"hello": "world"}) }) router.Run(":8080")}如果我fetch从 Firefox 控制台(Ubuntu 上的 97.0.2(64 位))执行操作:fetch('http://localhost:8080/') .then(response => response.json()) .then(data => console.log(data));我收到以下错误:Content Security Policy: The page’s settings blocked the loading of a resource at http://localhost:8080/ Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource.同时,如果我使用curl从终端执行相同的 HTTP GET 请求,我会得到正确的结果:curl -X GET http://localhost:8080/{"hello":"world"}是否可以使用浏览器测试 Go gin 服务器?
- 1 回答
- 0 关注
- 215 浏览
添加回答
举报
0/150
提交
取消