【问题标题】:SOAP Could not connect to host PHPSOAP 无法连接到主机 PHP
【发布时间】:2015-04-12 17:02:00
【问题描述】:

我正在尝试连接到 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>";
*/
  }

我得到的错误是:

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() 上,soap 已启用。奇怪的是,当我使用 c9.io 时,它工作得非常好,但目前在我的本地主机上,我无法让它工作。 所以我最后得到的应该是一个xml文件,它输出使用跟踪号找到的结果。

【问题讨论】:

    标签: php api soap ups


    【解决方案1】:

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

    【讨论】:

    • 我遇到了同样的问题,但我在 php.ini 文件中没有看到 cURL 选项,所以如果找不到分号,我无法取消注释。有什么想法吗?
    • 你可能需要安装 curl。 apt-get install php5-curl /etc/init.d/apache2 restart 或soap可能未启用。检查你的 phpinfo() 和 ini
    • 添加到哪个目录?提前谢谢?
    • 从命令行执行“apt-get install php5-curl”来安装对php的curl支持
    【解决方案2】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-19
      • 1970-01-01
      相关资源
      最近更新 更多