Creates 'POST' request.
public post ( string $url, array | string $data = null, array $headers = [], array $options = [] ) : |
||
$url | string | target URL. |
$data | array | string | if array - request data, otherwise - request content. |
$headers | array | request headers. |
$options | array | request options. |
return | request instance. |
/** * @inheritDoc */ public function export() { $response = $this->httpClient->post($this->webhookUrl, Json::encode($this->getPayload()), ['Content-Type: application/json; charset=UTF-8'])->send(); if (!$response->getIsOk()) { throw new InvalidValueException("Unable to send logs to Slack: {$response->getContent()}", (int) $response->getStatusCode()); } }
/** * Sends the specified message. * This method should be implemented by child classes with the actual email sending logic. * @param Message $message the message to be sent * @return boolean whether the message is sent successfully */ protected function sendMessage($message) { $request = $this->httpclient->post($this->getUrl(), ['from' => $this->normalizeAddress($message->getFrom()), 'to' => $this->normalizeAddress($message->getTo()), 'cc' => $this->normalizeAddress($message->getCc()), 'bcc' => $this->normalizeAddress($message->getBcc()), 'subject' => $message->getSubject(), 'text' => $message->getTextBody(), 'html' => $message->getHtmlBody()], ['Authorization' => 'Basic ' . base64_encode('api:' . $this->apiKey)]); $response = $request->send(); if ($response->getIsOk()) { return true; } else { try { $data = Json::decode($response->content); if (!isset($data['message'])) { throw new InvalidParamException("'message' field in response data is not set"); } } catch (InvalidParamException $e) { throw new MailerException("Invalid response from Mailgun API", 0, $e); } throw new MailerException("Mailgun sending error: {$data['message']}"); } }
public function send($text = null, $icon = null, $attachments = []) { $this->httpclient->post($this->url, ['payload' => Json::encode($this->getPayload($text, $icon, $attachments))]); }
/** * Send a message to slack * @param string $text message text * @param string $emoji emoji icon * @param array $attachments attachments (@see https://api.slack.com/incoming-webhooks) * @param string $channel channel to send to */ public function send($text = null, $emoji = null, $attachments = [], $channel = null) { $this->httpclient->post($this->url, ['payload' => Json::encode($this->getPayload($text, $emoji, $attachments, $channel))])->send(); }
public function query($url, $data) { $client = new Client(['baseUrl' => self::$baseUrl]); $response = $client->post($url, $data, ['Authorization' => 'Token 1d06237cf740861ef28bcfd9fa3994097c1b50b5', 'X-Secret' => self::$token])->setFormat(Client::FORMAT_JSON)->send(); if ($response->isOk) { return $response->data; } return false; }
public function query($url, $data) { $client = new Client(['baseUrl' => $this->baseUrl]); $response = $client->post($url, $data, ['Authorization' => 'Token ' . $this->token, 'X-Secret' => $this->secret])->setFormat(Client::FORMAT_JSON)->send(); if ($response->isOk) { return $response->data; } else { print_r($response); } return false; }