简体   繁体   中英

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. 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. On my phpinfo(), soap is enabled. What is strange, is that when I used c9.io, it worked perfectly fine, but currently on my localhost, I cannot get it working. So what I get at the end should be an xml file that outputs the results found using the tracking number.

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

UPS is upgrading the communication security protocols for all web-based applications, including UPS APIs. Please contact your company's IT department or development team to ensure that any security protocols currently used meet the TLS 1.2 requirement. If Java is enabled, it must be version 1.7 or higher to use 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.

If you are unable to do so, modify the endpoint URL to use temp-onlinetools.ups.com as the domain. 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. If you choose to use this environment, please provide the date you expect to be TLS compliant.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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