SOAP无法连接到主机PHP

SOAP无法连接到主机PHP,php,api,soap,ups,Php,Api,Soap,Ups,我正在尝试连接到UPS API以检索信息,但无法使其正常工作。我正在使用以下代码: //die(phpinfo()); //Configuration $access = "ACCESS NUMBER"; $userid = "USERNAME"; $passwd = "PASSWORD"; $wsdl = "wsdl/Track.wsdl"; //wsdl path $operation = "ProcessTrack"; $endpointurl = 'htt

我正在尝试连接到UPS API以检索信息,但无法使其正常工作。我正在使用以下代码:

  //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>";
*/
  }
我刚从网站下载了UPS API。在我的phpinfo()上,启用了soap。奇怪的是,当我使用c9.io时,它工作得非常好,但目前在我的本地主机上,我无法让它工作。
因此,我最后得到的应该是一个xml文件,它输出使用跟踪号找到的结果。

您需要在本地PHP安装中启用CURL。

UPS正在升级所有基于web的应用程序的通信安全协议,包括UPS API。 请联系贵公司的IT部门或开发团队,以确保当前使用的任何安全协议都符合TLS 1.2要求。如果启用了Java,则必须是1.7版或更高版本才能使用TLS1.2

如果在发布到API时遇到间歇性连接问题,我们建议在应用程序中实现重试逻辑,因为它在下一次尝试时会立即缓解


如果无法执行此操作,请修改端点URL以使用temp-onlinetools.ups.com作为域。这是一个临时环境,可供因升级而遇到连接问题的用户使用。如果此建议的更改解决了此问题,您将需要修改您的解决方案,以便使用TLS v1.2安全协议或更高版本连接到API,因为这是一个临时环境。如果您选择使用此环境,请提供您希望符合TLS的日期。

我也有同样的问题,但我在php.ini文件中没有看到cURL选项,因此如果分号不在哪里,我无法取消对其的注释。有什么想法吗?你可能需要安装curl。apt get install php5 curl/etc/init.d/apache2 restart或soap可能未启用。在phpinfo()中检查它,然后将它添加到哪个目录中?提前感谢?从命令行执行“apt get install php5 curl”以安装对php的curl支持
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 )