コード例 #1
0
ファイル: CurlTest.php プロジェクト: Tobur/BeSimpleSoapClient
 public function testGetResponseStatusCode()
 {
     $curl = new Curl(array('proxy_host' => false));
     $curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT));
     $this->assertEquals(200, $curl->getResponseStatusCode());
     $curl->exec(sprintf('http://localhost:%d/404.txt', WEBSERVER_PORT));
     $this->assertEquals(404, $curl->getResponseStatusCode());
 }
コード例 #2
0
 /**
  * Perform HTTP request with cURL.
  *
  * @param SoapRequest $soapRequest SoapRequest object
  *
  * @return SoapResponse
  */
 private function __doHttpRequest(SoapRequest $soapRequest)
 {
     // HTTP headers
     $soapAction = $soapRequest->getAction();
     $headers = array('Content-Type:' . $soapRequest->getContentType() . '; action="' . $soapAction . '"', 'SOAPAction: "' . $soapAction . '"');
     // execute HTTP request with cURL
     $responseSuccessfull = $this->curl->exec($soapRequest->getLocation(), $soapRequest->getContent(), $headers);
     // tracing enabled: store last request header and body
     if ($this->tracingEnabled === true) {
         $this->lastRequestHeaders = $this->curl->getRequestHeaders();
         $this->lastRequest = $soapRequest->getContent();
     }
     // in case of an error while making the http request throw a soapFault
     if ($responseSuccessfull === false) {
         // get error message from curl
         $faultstring = $this->curl->getErrorMessage();
         throw new \SoapFault('HTTP', $faultstring);
     }
     // tracing enabled: store last response header and body
     if ($this->tracingEnabled === true) {
         $this->lastResponseHeaders = $this->curl->getResponseHeaders();
         $this->lastResponse = $this->curl->getResponseBody();
     }
     // wrap response data in SoapResponse object
     $soapResponse = SoapResponse::create($this->curl->getResponseBody(), $soapRequest->getLocation(), $soapRequest->getAction(), $soapRequest->getVersion(), $this->curl->getResponseContentType());
     return $soapResponse;
 }
コード例 #3
0
 /**
  * Perform HTTP request with cURL.
  *
  * @param SoapRequest $soapRequest SoapRequest object
  *
  * @return SoapResponse
  */
 private function __doHttpRequest(SoapRequest $soapRequest)
 {
     // HTTP headers
     $soapVersion = $soapRequest->getVersion();
     $soapAction = $soapRequest->getAction();
     if (SOAP_1_1 == $soapVersion) {
         $headers = array('Content-Type:' . $soapRequest->getContentType(), 'SOAPAction: "' . $soapAction . '"');
     } else {
         $headers = array('Content-Type:' . $soapRequest->getContentType() . '; action="' . $soapAction . '"');
     }
     $location = $soapRequest->getLocation();
     $content = $soapRequest->getContent();
     /*
      * Work around missing header/php://input access in PHP cli webserver by
      * setting headers additionally as GET parameters and SOAP request body
      * explicitly as POST variable
      */
     if ($this->cliWebserverWorkaround === true) {
         if (strpos($location, '?') === false) {
             $location .= '?';
         } else {
             $location .= '&';
         }
         $location .= SoapMessage::CONTENT_TYPE_HEADER . '=' . urlencode($soapRequest->getContentType());
         $location .= '&';
         $location .= SoapMessage::SOAP_ACTION_HEADER . '=' . urlencode($soapRequest->getAction());
         $content = http_build_query(array('request' => $content));
         $headers = array();
     }
     // execute HTTP request with cURL
     $responseSuccessfull = $this->curl->exec($location, $content, $headers);
     // tracing enabled: store last request header and body
     if ($this->tracingEnabled === true) {
         $this->lastRequestHeaders = $this->curl->getRequestHeaders();
         $this->lastRequest = $soapRequest->getContent();
     }
     // in case of an error while making the http request throw a soapFault
     if ($responseSuccessfull === false) {
         // get error message from curl
         $faultstring = $this->curl->getErrorMessage();
         throw new \SoapFault('HTTP', $faultstring);
     }
     // tracing enabled: store last response header and body
     if ($this->tracingEnabled === true) {
         $this->lastResponseHeaders = $this->curl->getResponseHeaders();
         $this->lastResponse = $this->curl->getResponseBody();
     }
     // wrap response data in SoapResponse object
     $soapResponse = SoapResponse::create($this->curl->getResponseBody(), $soapRequest->getLocation(), $soapRequest->getAction(), $soapRequest->getVersion(), $this->curl->getResponseContentType());
     return $soapResponse;
 }
コード例 #4
0
 public function testGetResponseStatusMessage()
 {
     $this->startPhpWebserver();
     $curl = new Curl();
     $curl->exec('http://localhost:8000/curl.txt');
     $this->assertEquals('OK', $curl->getResponseStatusMessage());
     $curl->exec('http://localhost:8000/404.txt');
     $this->assertEquals('Not Found', $curl->getResponseStatusMessage());
     $this->stopPhpWebserver();
 }