错误 - USPS地址验证PHP API

时间:2013-04-29 04:41:16

标签: php xml usps

我已下载代码&从" https://github.com/VinceG/USPS-php-api"创建演示对于USPS-php-api。

我得到这样的错误" Array()bool(true)错误:没有设置URL! "

如果您有任何解决方案,请与我们联系。

我使用了以下代码。


<?php
require_once('../USPSAddressVerify.php');
$verify = new USPSAddressVerify('xxxxxxxxxxxx'); // I have used correct username
$address = new USPSAddress;
$address->setFirmName('Apartment');
$address->setApt('100');
$address->setAddress('9200 Milliken Ave');
$address->setCity('Rancho Cucomonga');
$address->setState('CA');
$address->setZip5(91730);
$address->setZip4('');

$verify->addAddress($address);
print_r($verify->verify());
print_r($verify->getArrayResponse());
var_dump($verify->isError());

if($verify->isSuccess()) {
    echo 'Done';
} else {
    echo 'Error: ' . $verify->getErrorMessage();
}

1 个答案:

答案 0 :(得分:0)

我所做的是在USPSBase课程中,在doRequest方法中,注释掉这一行......

$opts[CURLOPT_URL] = self::$testMode ? self::TEST_API_URL : self::LIVE_API_URL

...并修改此行......

$ch = curl_init();

..是......

$ch = curl_init(self::$testMode ? self::TEST_API_URL : self::LIVE_API_URL);

...而且,由于可能存在相关问题,我不得不添加......

$opts[CURLOPT_FOLLOWLOCATION] = !ini_get('open_basedir');

... ...后

$opts[CURLOPT_POSTFIELDS] = http_build_query($this->getPostData(), null, '&');

......满足这个警告......

curl_setopt_array(): CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set

注意:这仅使用地址验证功能进行测试!