简体   繁体   English

我使用哪个IP地址调用外部API?

[英]Which IP address am I using to call an external API?

I have a PHP script that I use to geocode addresses using the Google Geocode API. 我有一个PHP脚本,可用于使用Google Geocode API对地址进行地理编码。 This works well on my test server. 这在我的测试服务器上运行良好。 I use the URL 我使用网址

https://maps.googleapis.com/maps/api/geocode/json?key=SECRET&address=ADDRESS&sensor=false

But when deployed to the production server, I get this error message: 但是,当部署到生产服务器时,我收到此错误消息:

{ "error_message" : "This IP, site or mobile application is not authorized to use this API key.", "results" : [], "status" : "REQUEST_DENIED" }

The server has multiple IP addresses, and I do not know the IP range or all of the IP addresses, and therefore, I am unable to add them in Google's API console . 该服务器具有多个IP地址,并且我不知道IP范围或所有IP地址,因此,我无法在Google的API控制台中添加它们。 It is not the public IP address of the server. 不是服务器的公共IP地址

So how do I find out which IP address my production server is using for calling the API? 那么,如何找出生产服务器用来调用API的IP地址?

I found a workaround for the problem, however, it does not really answer my original question, which I will leave open. 我找到了解决该问题的方法,但是它并不能真正回答我原来的问题,我将继续公开。

It is possible to add the userIp -parameter, according to some well-hidden Google API documentation . 根据一些隐藏的Google API文档 ,可以添加userIp参数。

So I successfully used the call 所以我成功使用了通话

https://maps.googleapis.com/maps/api/geocode/json?key=SECRET&address=ADDRESS&sensor=false&userIp=11.22.33.44

where the IP address was one of the allowed IP-addresses. IP地址是允许的IP地址之一。

The IP address of the server can be retrieved from $_SERVER['SERVER_ADDR'] 可以从$_SERVER['SERVER_ADDR']检索服务器的IP地址。

You can try emailing the IP address of the server to yourself when you see the error message. 看到错误消息后,您可以尝试通过电子邮件将服务器的IP地址发送给自己。

More info: 更多信息:

http://www.php.net/manual/en/reserved.variables.server.php http://www.php.net/manual/en/reserved.variables.server.php

The IP address of the server which is being used on external request can be found by making a HTTP request to http://ip.appspot.com/ 通过向http://ip.appspot.com/发出HTTP请求,可以找到用于外部请求的服务器的IP地址。

PHP code: PHP代码:

<?php
echo file_get_contents('http://ip.appspot.com/');
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Symfony2控制器中获取外部IP地址? - How do I get the external IP address in a Symfony2 controller? 导入时对二进制IP地址的API调用显示奇怪的格式 - API call on a binary IP address shows weird format when imported 我需要调用一个可以在 windows 中运行但在 linux 中不能运行的 API,我收到 401 错误 - I need to call an API which is working in windows but not in linux, I am getting 401 error 如何使用PHP简化IP地址? 尝试long2ip(ip2long(address)) - How can I simplify an IP address using PHP? Trying long2ip(ip2long(address)) 为什么网站上没有显示 url 我该如何解决这个问题是因为我使用的是 ip 地址而不是 url 示例,例如“myipaddress”/mvc? - Why url is not displayed on the website how can i solve this issue is it because am using ip address instead of url example like "myipaddress"/mvc ?? 我使用哪种方法获取每台计算机的IP地址 - Which method I use for get each computer ip address 我为每个系统获得相同的IP - 如何通过PHP编码获取IP地址 - I am getting same IP for every system - How to get IP Address via PHP coding 计算哪个子网是IP地址 - Calculate in which subnet is IP address IP地址的正则表达式不完整 - REGEX for IP address which is incomplete 我如何获取局域网中使用php从本地服务器访问网页的系统的IP地址 - How can i get IP address of systems in a local network which accessing the webpage from local server using php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM