My English is not good, please forgive me
I have an API interface for querying weather, which uses the visitor's IP to obtain weather information about the city being queried
But I used HTTP in combination with HTTP reqeust to find out that it is the city where my server IP is located
I also understand that the request is sent from the server side, how can it use the visitor's IP
I tried X-Forwarded For, but it's not possible
Hi and welcome to the forum.
Just to mention to you:
For the first day or so, you have a LIMITED amount of questions/posts you can make.
So be careful how you answer as you may run out of reply allowances before you know it.
Allowing most devices to be accessed from the internet is/CAN be DANGEROUS!
So you are (Examples used here) 4.4.4.4
(I have no imagination) and your friend is 7.7.7.7
There is a node that can get you the weather which may be of use/interest to you.
openweather node
So - back to your question:
In the perfect world, you would put their IP number (7.7.7.7
) in your code to ask for the weather.
This shouldn't have any open ports on YOUR machine.
I hope this is of some help to you.
Seems in your case the weather provider (3rd party ?) uses client IP, it is correct ?
If so, it may be impossible to spoof ip to him, or you need to read vendor's doc to find out how, to pass IP to it's IP.
Usually, services which uses client IP not allow you to add ip to query. You can use local geoip database or geoip service to get first client location and then query weather service with this location instead of IP.
If weather service is controlled by you, you need to setup it to accept X-forwarded-for: header. such headers are custom, there is no "standard" headers for forwarded IP (and more over such as x-forwarded overwriten if system uses it.
I think the real question here is how does the end-user trigger the request?
For now, lets assume that this is using Dashboard and switching to a specific Dashboard Tab triggers an update request. I think that your server should be doing the lookup and passing the city onto the request rather than letting the request service look it up themselves.
x-forwarded-for
is only applicable if there is a proxy in the architecture such that the client goes through the proxy to get to your Node-RED server. You should note, however, that trying to track the actual client IP is notoriously difficult in some circumstances - and indeed, in some instances is impossible. Additionally, assuming that the IP address (you need the PUBLIC IP of course) is actually associated with the users location is often flawed, for example, mine generally tracks to a data centre 20+ miles away and sometimes even further depending on what is happening in the BT network.
It is much better to ask the user what location they want and to persist that so they don't have to keep entering it but can change it should they need/want to. If you want to be particularly kind to your users, you can add a request for the browser to provide the location, it may sometimes provide a more accurate result but you have to allow for a failed browser request since the user may simply deny the request.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.