Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function postJson($url, array $fields) {
- $client = curl_init();
- $data = json_encode($fields);
- $headers = $this->flattenHeaders();
- $headers[] = 'Content-Length: ' . strlen($data);
- // Default parameters
- curl_setopt_array($client, [
- CURLOPT_TIMEOUT => 30,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
- CURLOPT_USERPWD => $this->authHeader,
- CURLOPT_URL => $this->buildUrl($url),
- CURLOPT_POST => true,
- CURLOPT_POSTFIELDS => $data,
- CURLOPT_HTTPHEADER => $headers,
- ]);
- $body = curl_exec($client);
- if (curl_errno($client)) {
- throw new CurlException(curl_error($client), curl_errno($client));
- }
- $result = CurlResponse::factory($body, $client);
- curl_close($client);
- return $result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement