2
我试图连接到UPS API来检索信息,但我无法得到它的工作。我使用此代码:SOAP无法连接到主机PHP
//die(phpinfo());
//Configuration
$access = "ACCESS NUMBER";
$userid = "USERNAME";
$passwd = "PASSWORD";
$wsdl = "wsdl/Track.wsdl"; //wsdl path
$operation = "ProcessTrack";
$endpointurl = 'https://wwwcie.ups.com/webservices/Track'; //https://onlinetools.ups.com/ups.app/xml/Track or https://wwwcie.ups.com/webservices/Track
$outputFileName = "XOLTResult.xml";
function processTrack()
{
//create soap request
$req['RequestOption'] = '15';
$tref['CustomerContext'] = 'Add description here';
$req['TransactionReference'] = $tref;
$request['Request'] = $req;
$request['InquiryNumber'] = TRACKING NUMBER;
$request['TrackingOption'] = '02';
//echo "Request.......\n";
print_r($request);
//echo "\n\n";
return $request;
}
try
{
$mode = array
(
'soap_version' => 'SOAP_1_1', // use soap 1.1 client
'trace' => 1
);
// initialize soap client
$client = new SoapClient($wsdl , $mode);
//set endpoint url
$client->__setLocation($endpointurl);
//create soap header
$usernameToken['Username'] = $userid;
$usernameToken['Password'] = $passwd;
$serviceAccessLicense['AccessLicenseNumber'] = $access;
$upss['UsernameToken'] = $usernameToken;
$upss['ServiceAccessToken'] = $serviceAccessLicense;
$header = new SoapHeader('http://www.ups.com/XMLSchema/XOLTWS/UPSS/v1.0','UPSSecurity',$upss);
$client->__setSoapHeaders($header);
//get response
$resp = $client->__soapCall($operation ,array(processTrack()));
//get status
//echo "Response Status: " . $resp->Response->ResponseStatus->Description ."\n";
//save soap request and response to file
$fw = fopen($outputFileName , 'w');
fwrite($fw , "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" . $client->__getLastResponse() . "\n");
fclose($fw);
//echo "<br> Request:<br>";
//print_r("<?xml version=\"1.0\" encoding=\"UTF-8\" \n" . $client->__getLastResponse() . "\n");
header('Content-type: text/xml');
echo $client->__getLastResponse();
}
catch(Exception $ex)
{
print_r($ex);
/*
header('Content-type: text/xml');
echo "<xml>Error</xml>";
*/
}
我得到的错误是:
Array ([Request] => Array ([RequestOption] => 15 [TransactionReference] => Array ([CustomerContext] => Add description here)) [InquiryNumber] => [TRACKING NUMBER] [TrackingOption] => 02) SoapFault Object ([message:protected] => Could not connect to host [string:Exception:private] => [code:protected] => 0 [file:protected] => /Applications/XAMPP/xamppfiles/htdocs/kestrak/php/ups.php [line:protected] => 58 [trace:Exception:private] => Array ([0] => Array ([function] => __doRequest [class] => SoapClient [type] => -> [args] => Array ([0] => [CREDENTIALS]Add description here[TRACKING NUMBER] [1] => https://wwwcie.ups.com/webservices/Track [2] => http://onlinetools.ups.com/webservices/TrackBinding/v2.0 [3] => 1 [4] => 0)) [1] => Array ([file] => /Applications/XAMPP/xamppfiles/[DIRECTORY] [line] => 58 [function] => __soapCall [class] => SoapClient [type] => -> [args] => Array ([0] => ProcessTrack [1] => Array ([0] => Array ([Request] => Array ([RequestOption] => 15 [TransactionReference] => Array ([CustomerContext] => Add description here)) [InquiryNumber] => [TRACKING NUMBER] [TrackingOption] => 02))))) [previous:Exception:private] => [faultstring] => Could not connect to host [faultcode] => HTTP)
我刚刚下载的UPS API从网站。在我的phpinfo()上,肥皂已启用。奇怪的是,当我使用c9.io时,它工作得很好,但是目前在我的本地主机上,我无法正常工作。 所以我最后得到的应该是一个xml文件,输出使用跟踪号码找到的结果。
我有同样的问题,但我没有看到我的php.ini文件中的cURL选项,所以我不能取消分号如果它不是在哪里被发现的分号。有任何想法吗? – Supplement
您可能需要安装卷曲。 apt-get install php5-curl /etc/init.d/apache2 restart 或soap可能未启用。检查你的phpinfo()和ini – andyknas
我在什么目录中添加它?提前致谢? – Supplement