Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
Ir a la ginebra: obtener datos del navegador local

Tengo un servidor simple escrito con Go Gin:

 package main import ( "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") }

Si busco desde la consola de Firefox ( fetch (64 bits) en Ubuntu):

 fetch('http://localhost:8080/') .then(response => response.json()) .then(data => console.log(data));

Obtuve el siguiente error:

 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.

Mientras que, si hago la misma solicitud HTTP GET desde una terminal con curl , obtengo el resultado correcto:

 curl -X GET http://localhost:8080/ {"hello":"world"}

¿Es posible probar el servidor Go gin usando el navegador?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Si intenta realizar una solicitud ajax desde una ubicación diferente a la ubicación de la solicitud de solicitud, la Content Security Policy (CSP) bloqueará la solicitud, lo que ayuda a detectar y mitigar ciertos tipos de ataques. Puede leer más sobre la CSP aquí .

Para que la búsqueda funcione, debe ir a la misma ubicación y realizar una solicitud de búsqueda desde esa ubicación, en su caso, es http://localhost:8080/ .

Nota: dado que ha definido la ruta raíz para devolver json cuando abre la ubicación en el navegador, lo que puede generar una solicitud GET y la respuesta json se devolverá en el navegador.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!