상속: extends AbstractTransportException
예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function send($uri, $payload)
 {
     try {
         $response = $this->client->post($uri, ['headers' => $this->getHeaders(true), 'body' => $payload]);
     } catch (AdapterException $e) {
         throw TcpException::transportError($e);
     } catch (BadResponseException $e) {
         throw HttpException::httpError($e->getMessage(), $e->getResponse()->getStatusCode(), $e);
     }
     return $response->getBody(true);
 }
 /** {@inheritdoc} */
 public function send($endpoint, $payload)
 {
     try {
         $response = $this->httpAdapter->post($endpoint, ['Content-Type' => 'text/xml; charset=UTF-8'], $payload);
     } catch (HttpAdapterException $e) {
         throw TransportException::transportError($e);
     }
     if ($response->getStatusCode() !== 200) {
         throw HttpException::httpError($response->getReasonPhrase(), $response->getStatusCode());
     }
     return (string) $response->getBody();
 }
 /**
  * {@inheritdoc}
  */
 public function send($url, $payload)
 {
     try {
         $response = $this->client->setMethod('POST')->setUri($url)->setRawBody($payload)->setHeaders($this->getHeaders(true))->send();
     } catch (RuntimeException $e) {
         throw TcpException::transportError($e);
     }
     if ($response->getStatusCode() !== 200) {
         throw HttpException::httpError($response->getReasonPhrase(), $response->getStatusCode());
     }
     return $response->getBody();
 }
 /** {@inheritdoc} */
 public function send($uri, $payload)
 {
     try {
         /** @var $response Response */
         $response = $this->browser->post($uri, $this->getHeaders(true), $payload);
     } catch (RuntimeException $e) {
         throw TcpException::transportError($e);
     }
     if ($response->getStatusCode() !== 200) {
         throw HttpException::httpError($response->getReasonPhrase(), $response->getStatusCode());
     }
     return $response->getContent();
 }
예제 #5
0
 /** {@inheritdoc} */
 public function send($uri, $payload)
 {
     curl_setopt_array($this->handle, [CURLOPT_URL => $uri, CURLOPT_POSTFIELDS => $payload, CURLOPT_HTTPHEADER => explode("\r\n", $this->getHeadersString())]);
     $response = curl_exec($this->handle);
     if ($response === false || strlen($response) < 1) {
         throw TcpException::transportError(curl_error($this->handle));
     }
     $code = curl_getinfo($this->handle, CURLINFO_HTTP_CODE);
     if ($code !== 200) {
         throw HttpException::httpError(curl_error($this->handle), $code);
     }
     return substr($response, curl_getinfo($this->handle, CURLINFO_HEADER_SIZE));
 }
 public function send($uri, $payload)
 {
     $request = (new Request())->setUri($uri)->setMethod('POST')->setBody($payload)->setProtocol('1.1')->setAllHeaders($this->getHeaders(true));
     try {
         $response = $this->client->request($request)->wait();
     } catch (SocketException $e) {
         throw TcpException::transportError($e);
     }
     if ($response->getStatus() !== 200) {
         throw HttpException::httpError('Invalid response code', $response->getStatus());
     }
     return $response->getBody();
 }
 /** {@inheritdoc} */
 public function send($uri, $payload)
 {
     $context = stream_context_create(['http' => ['method' => 'POST', 'header' => $this->getHeadersString(), 'content' => $payload]]);
     $response = @file_get_contents($uri, false, $context);
     if ($response === false) {
         $error = error_get_last();
         if (strpos($error['message'], 'HTTP request failed')) {
             $matched = preg_match('|HTTP/1.[0-1]\\s+(?<code>\\d+)|', $error['message'], $matches);
             throw HttpException::httpError($error['message'], $matched ? $matches['code'] : null);
         }
         throw TcpException::transportError($error['message']);
     }
     return $response;
 }
 /**
  * {@inheritdoc}
  */
 public function send($url, $payload)
 {
     try {
         $response = $this->client->setUri($url)->setHeaders($this->getHeaders())->setRawData($payload)->request('POST');
     } catch (HttpClientAdapterException $e) {
         throw TcpException::transportError($e);
     } catch (HttpClientException $e) {
         throw TcpException::transportError($e);
     }
     if ($response->getStatus() !== 200) {
         throw HttpException::httpError($response->getMessage(), $response->getStatus());
     }
     return $response->getBody();
 }
예제 #9
0
 /** {@inheritdoc} */
 public function send($endpoint, $payload)
 {
     try {
         $request = $this->messageFactory->createRequest('POST', $endpoint, ['Content-Type' => 'text/xml; charset=UTF-8'], $payload);
         $response = $this->client->sendRequest($request);
         if ($response->getStatusCode() !== 200) {
             throw HttpException::httpError($response->getReasonPhrase(), $response->getStatusCode());
         }
         return (string) $response->getBody();
     } catch (PsrHttpException $e) {
         $response = $e->getResponse();
         throw HttpException::httpError($response->getReasonPhrase(), $response->getStatusCode());
     } catch (ClientException $e) {
         throw TransportException::transportError($e);
     }
 }
예제 #10
0
 /**
  * {@inheritdoc}
  */
 public function send($uri, $payload)
 {
     try {
         $response = $this->client->post($uri, $this->getHeaders(true), $payload)->send();
     } catch (CurlException $e) {
         throw TcpException::transportError($e);
     } catch (CompatCurlException $e) {
         throw TcpException::transportError($e);
     } catch (BadResponseException $e) {
         throw HttpException::httpError($e->getMessage(), $e->getResponse()->getStatusCode(), $e);
     } catch (ServerErrorResponseException $e) {
         throw HttpException::httpError($e->getMessage(), $e->getResponse()->getStatusCode(), $e);
     } catch (ClientErrorResponseException $e) {
         throw HttpException::httpError($e->getMessage(), $e->getResponse()->getStatusCode(), $e);
     }
     return $response->getBody(true);
 }