通过代理服务器访问 Import.io API

Accessing Import.io API through a proxy server

我在使用 import.io API 时遇到问题。

尽管我的应用程序在英国使用和部署,但由于 Import.IO 的服务器部署在美国,它会 return(对于某些商店)不正确的货币和价格数据。我与那里的支持团队进行了交谈,他们帮助我告知我可以为 Import API.

托管代理服务器

我设法获得了一个 AWS 实例 运行 并安装了 Squid 作为代理服务器。我更改了我的 Firefox 连接设置并成功地通过此代理服务器浏览网页(也验证了我的 ip 是我服务器的 IP)

但是,我不完全确定我应该如何从我的应用程序中调用导入库。

该应用程序是在 PHP 中构建的,我将如何生成 URL 来调用的当前示例是:

public function generateCall( $import_key, $url )
{
    return sprintf(
        'https://api.import.io/store/data/%s/_query?input/webpage/url=%s&_user=XXXX&_apikey=%s',
        $import_key, urlencode( $url ), self::$apikey
    );
}

我正在直接调用 api.import.io 服务器。

如果我对你的问题的理解正确,你正试图通过你的 squid 代理访问 import.io 资源。 有几种选择

  1. 将系统代理设置为 squid。
  2. 将 设置为鱿鱼。

您可以使用 CURL 获取 API。 然后,您可以找到某个国家/地区的代理来按国家/地区获取 API 数据。

$user = 'User';
$key = 'key';
$url = 'https://api.import.io/store/data/%s/_query?input/webpage/url=%s&_user=XXXX&_apikey=%s';
$proxy = '127.0.0.1:8888';
//$proxyauth = 'user:password';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);

echo $curl_scraped_page;