1

我已经下载了代码并从“创建演示” https://github.com/VinceG/USPS-php-api ”下载了代码并为 USPS-php-api 创建了演示。

我收到这样的错误“Array () bool(true) Error: No URL set!”

如果您有任何解决方案,请告诉我。

我使用了以下代码。


<?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();
}

4

1 回答 1

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

注意:这仅通过地址验证功能进行了测试!

于 2013-07-03T16:42:11.523 回答