I want to integrate ReCAPTCHA to my GAE Golang web application. In order to verify a captcha, I need to get user's IP address. How can I fetch user's IP address from a form post?
相关问题
- java.lang.NullPointerException at java.io.PrintWri
- Golang mongodb aggregation
- __call__() missing 1 required positional argument:
- How to flatten out a nested json structure in go
- how to install private repo using glide golang
相关文章
- Can I run a single test in a suite?
- Is there a size limit for HTTP response headers on
- How to check if a request was cancelled
- Is it possible to implement an interface with unex
- appcfg.py command not found
- How to access value of first index of array in Go
- PostgreSQL field data type for IPv4 addresses
- Google app engine datastore string encoding proble
inside your handler function call r.RemoteAddr to receive ip:port
like this:
update 02/15/2017 as @Aigars Matulis pointed out, in current version there is already a function todo this
This worked for me. I run go in 8081 and made a request from port 8080.
Output:
The Referer and Origin have my client IP.
Output:
Use net.SplitHostPort:
The answers above neglect to check if user's IP is forwarded by a proxy. In a lot of cases, the IP that you will find in the RemoteAddr is the IP of a proxy that is forwarding the user's request to you - not the user's IP address!
A more accurate solution would look like this: