- With issues:
- Use the search tool before opening a new issue. ✅
- Please provide source code and commit sha if you found a bug.
- Review existing issues and provide feedback or react to them.
Description
I am unable to make curl request to my gin server. However I am able to make all request using a browser.
How to reproduce
package main
import "github.com/gin-gonic/gin"
func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Run() // listen and serve on 0.0.0.0:8080
}
Expectations
$ curl http://localhost:8080/ping
{
"message": "pong"
}
Actual result
$ curl -i http://localhost:8080/ping
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Tue, 29 Aug 2023 09:59:34 GMT
Content-Length: 19
404 page not found
I am able to make a request to this endpoint through a browser but not using curl. Is there some configuration missing? If so is there a place for me to document it so others won't run into this in the future?
Environment
- go version: 1.21.0
- gin version (or commit ref): v1.9.1
- operating system: darwin/amd64
Comment From: jooyyy
You get 404 means there is one process listening on 8080, your code seems to have no problem, but you should make sure the latest code is running on the 8080, not the old version or another process.
Comment From: tinkrtailor
@jooyyy If a browser is getting a 200 response from the endpoint why would curl be getting a different one. It must mean that the up to date code is running that port.
Comment From: tinkrtailor
Hmm strange, seems to be working now. Perhaps there was a rogue process running on 8080 and the browser. But very strange that Gin would be able to start up when there is another process listening on the same port, no?
Comment From: tinkrtailor
Closing this issue because of its automagical resolution