2013-04-29 88 views
1

我已经下载代码&从“https://github.com/VinceG/USPS-php-api”为USPS-php-api创建演示。错误 - USPS地址验证PHP API

我有错误这样的“阵列()布尔(真)错误:没有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(); 
} 

+0

什么是在USPSAddressVerify.php中设置的网址? – 2013-04-29 05:04:47

+0

请注意作者在GitHub上的公开问题,其中应该发布解决方案:https://github.com/VinceG/USPS-php-api/issues/5 – Matt 2013-04-29 05:10:11

+0

我能够通过注释掉#行来重新创建错误# ''$ opts [CURLOPT_URL] = self :: $ testMode? self :: TEST_API_URL:self :: LIVE_API_URL;'USPSBase.php'中。确保你正在设置'$ opts [CURLOPT_URL]'。 – Sean 2013-04-29 06:06:43

回答

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 

注意:这只有已经使用地址验证功能进行了测试!