title: Couldnt connect to host Royal mail shipping api SOAP
body: <p>Hello im trying to connect to royalmail shipping api and gettting couldnt connect to host every time. I'm trying to contact royal mail but didnt get proper answer to the issue.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>ini_set('default_socket_timeout', 120);
  ini_set('soap.wsdl_cache_enabled',1);
  ini_set('soap.wsdl_cache_ttl',1);
  
  $api_password = "xxxxx";
  $api_username = "xxxxxxAPI";
  $api_application_id = "xxxxx";
  $api_service_type = "D";
  $api_service_code = "SD1";
  $api_service_format = "";
  $clientId='xxxxx';
  $clientSecret='xxxxxx';
  $api_service_enhancements = "";
  
  $data = new ArrayObject();
  $data-&gt;order_tracking_id = "";
  $data-&gt;shipping_name = "Jon Doe";
  $data-&gt;shipping_company = "SS";
  $data-&gt;shipping_address1 = "23, Some Road"; 
  $data-&gt;shipping_address2 = "";
  $data-&gt;shipping_town = "London";
  $data-&gt;shipping_postcode = "E1";
  $data-&gt;order_tracking_boxes = "0";
  $data-&gt;order_tracking_weight = "1000";    
  
  $time = gmdate('Y-m-d\TH:i:s');
  $created = gmdate('Y-m-d\TH:i:s\Z');
  $nonce = mt_rand();
  $nonce_date_pwd = pack("A*",$nonce) . pack("A*",$created) . pack("H*", sha1($api_password));
  $passwordDigest = base64_encode(pack('H*',sha1($nonce_date_pwd)));
  $ENCODEDNONCE = base64_encode($nonce);
  
  
  $soapclient_options = array(); 
  $soapclient_options['cache_wsdl'] = 'WSDL_CACHE_NONE'; 
  $soapclient_options['stream_context']= stream_context_create(
                              array(
                                  'http' =&gt;
                                      array(
                                          'header'           =&gt; implode(
                                              "\r\n",
                                              array(
                                                  'Accept: application/soap+xml',
                                                  'X-IBM-Client-Id: ' . $clientId,
                                                  'X-IBM-Client-Secret: ' . $clientSecret,
                                              )
                                          ),
                                      ),
                              )
                          );
  $soapclient_options['trace'] = true;
  $soapclient_options['ssl_method'] = 'SOAP_SSL_METHOD_SSLv3';
  $soapclient_options['exceptions'] = true;
  $soapclient_options['location'] = 'https://api.royalmail.com/shipping/onboarding';
  
  //launch soap client
  $client = new SoapClient(dirname(__FILE__) . "/SAPI/ShippingAPI_V2_0_9.wsdl", $soapclient_options);
  $client-&gt;__setLocation($soapclient_options['location']);
  
  //headers needed for royal mail
  $HeaderObjectXML  = '&lt;wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
                        xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"&gt;
             &lt;wsse:UsernameToken wsu:Id="UsernameToken-000"&gt;
                &lt;wsse:Username&gt;'.$api_username.'&lt;/wsse:Username&gt;
                &lt;wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest"&gt;'.$passwordDigest.'&lt;/wsse:Password&gt;
                &lt;wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"&gt;'.$ENCODEDNONCE.'&lt;/wsse:Nonce&gt;
                &lt;wsu:Created&gt;'.$created.'&lt;/wsu:Created&gt;
             &lt;/wsse:UsernameToken&gt;
         &lt;/wsse:Security&gt;';
  
  //push the header into soap
  $HeaderObject = new SoapVar( $HeaderObjectXML, XSD_ANYXML );
  
  //push soap header
  $header = new SoapHeader( 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd', 'Security', $HeaderObject );
  $client-&gt;__setSoapHeaders($header);
  
  //build the request
  $request = array(
      'integrationHeader' =&gt; array(
          'dateTime' =&gt; $time,
          'version' =&gt; '1.0',
          'identification' =&gt; array(
              'applicationId' =&gt; $api_application_id,
              'transactionId' =&gt; $data-&gt;order_tracking_id
          )
      ),
      'requestedShipment' =&gt; array(
                                  'shipmentType' =&gt; array('code' =&gt; 'Delivery'),
                                  'serviceOccurence' =&gt; '1',
                                  'serviceType' =&gt; array('code' =&gt; $api_service_type),
                                  'serviceOffering' =&gt; array('serviceOfferingCode' =&gt; array('code' =&gt; $api_service_code)),
                                  'serviceFormat' =&gt; array('serviceFormatCode' =&gt; array('code' =&gt; $api_service_format)),
                                  'shippingDate' =&gt; date('Y-m-d'),
                                  'recipientContact' =&gt; array('name' =&gt; $data-&gt;shipping_name, 'complementaryName' =&gt; $data-&gt;shipping_company),
                                  'recipientAddress' =&gt; array('addressLine1' =&gt; $data-&gt;shipping_address1,  'addressLine2' =&gt; $data-&gt;shipping_address2, 'postTown' =&gt; $data-&gt;shipping_town, 'postcode' =&gt; $data-&gt;shipping_postcode),
                                  'items' =&gt; array('item' =&gt; array(
                                              'numberOfItems' =&gt; $data-&gt;order_tracking_boxes,
                                              'weight' =&gt; array( 'unitOfMeasure' =&gt; array('unitOfMeasureCode' =&gt; array('code' =&gt; 'g')), 'value' =&gt; ($data-&gt;order_tracking_weight*1000) //weight of each individual item
                                                               )
                                                                  )
                                                  )
                                  )               
  );
  
  
  //if any enhancements, add it into the array
  if($api_service_enhancements != "") {
      $request['requestedShipment']['serviceEnhancements'] = array('enhancementType' =&gt; array('serviceEnhancementCode' =&gt; array('code' =&gt; $api_service_enhancements)));
  }
  
  //try make the call
  try { 
      $response = $client-&gt;__soapCall( 'createShipment', array($request), array('soapaction' =&gt; 'https://api.royalmail.com/shipping/onboarding') );
  } catch (Exception $e) {
      //catch the error message and echo the last request for debug
      echo $e-&gt;getMessage(); 
      echo " REQUEST:\n" . $client-&gt;__getLastRequest() . "\n";
      die;
  }
  
  //check for any errors
  if(isset($response-&gt;integrationFooter-&gt;errors)) { 
      $build = "";
  
      //check it wasn't a single error message
      if(isset($response-&gt;integrationFooter-&gt;errors-&gt;error-&gt;errorCode)) { 
          $build .= $output_error-&gt;errorCode.": ".$output_error-&gt;errorDescription."&lt;br/&gt;"; 
      } else {
          //loop out each error message, throw exception will be added ehre
          foreach($response-&gt;integrationFooter-&gt;errors-&gt;error as $output_error) { 
              $build .= $output_error-&gt;errorCode.": ".$output_error-&gt;errorDescription."&lt;br/&gt;";
          }
      }
  
      echo $build; die;
  
  }
  
  print_r($response);
  
  echo "REQUEST:\n" . $client-&gt;__getLastRequest() . "\n";
  exit;   
  </code></pre>
  
  <p>The error I'm getting is:</p>
  
  <pre><code>Could not connect to host REQUEST: xxxxxkAPI xxxxxxx 2016-03-24T02:50:24Z 2016-03-24T02:50:241.0RMG-API-G-01DeliveryDSD12016-03-24Jon DoeSS23, Some RoadLondonE10g1000000
  </code></pre>
  
  <p>Any help would be really appreciated.</p>