简体   繁体   English

SOAP无法连接到主机PHP

[英]SOAP Could not connect to host PHP

I'm trying to connect to UPS API to retrieve info but I can't get it working. 我正在尝试连接到UPS API来检索信息,但无法正常工作。 I'm using this code: 我正在使用此代码:

  //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>";
*/
  }

The error I get is: 我得到的错误是:

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 )

I just downloaded the UPS API from the website. 我刚刚从网站下载了UPS API。 On my phpinfo(), soap is enabled. 在我的phpinfo()上,启用了soap。 What is strange, is that when I used c9.io, it worked perfectly fine, but currently on my localhost, I cannot get it working. 奇怪的是,当我使用c9.io时,它工作得很好,但是当前在我的本地主机上,我无法使其正常工作。 So what I get at the end should be an xml file that outputs the results found using the tracking number. 因此,我最后得到的应该是一个xml文件,该文件输出使用跟踪号找到的结果。

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

UPS is upgrading the communication security protocols for all web-based applications, including UPS APIs. UPS正在升级所有基于Web的应用程序的通信安全协议,包括UPS API。 Please contact your company's IT department or development team to ensure that any security protocols currently used meet the TLS 1.2 requirement. 请与您公司的IT部门或开发团队联系,以确保当前使用的任何安全协议都符合TLS 1.2要求。 If Java is enabled, it must be version 1.7 or higher to use TLS 1.2. 如果启用了Java,则必须使用1.7或更高版本才能使用TLS 1.2。

If you experience intermittent connectivity issues when posting to the APIs, we suggest implementing retry logic into your application as it should have immediate relief on the next attempt. 如果在发布到API时遇到间歇性的连接问题,我们建议在您的应用程序中实现重试逻辑,因为它可以在下次尝试时立即缓解。

If you are unable to do so, modify the endpoint URL to use temp-onlinetools.ups.com as the domain. 如果您不能这样做,请修改端点URL以将temp-onlinetools.ups.com用作域。 This is a temporary environment that has been made available for user who encounter connectivity problems due to the upgrades. 这是一个临时环境,可供因升级而遇到连接问题的用户使用。 If this suggested change resolves the issue, you will need to modify your solution to connect to the APIs using TLS v1.2 security protocol or higher since this temporary environment. 如果此建议的更改解决了此问题,则由于此临时环境,您将需要修改解决方案以使用TLS v1.2安全协议或更高版本连接到API。 If you choose to use this environment, please provide the date you expect to be TLS compliant. 如果选择使用此环境,请提供您希望符合TLS的日期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM