Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $url = 'env.host.com/api/endpoint';
- $data = [
- 'json' => '{"clockNo":"3021","startTime":"2019-10-17 17:09:39","endTime":"2019-10-17 17:09:39","workCentreNumber":"118","so":"1702-01","minutes":0,"source":"Scanner","active":1,"operation_id":"613","operation_type":"queue"}'
- ];
- $payload = http_build_query($data);
- //json=%7B%22clockNo%22%3A%223021%22%2C%22startTime%22%3A%222019-10-17+17%3A49%3A06%22%2C%22endTime%22%3A%222019-10-17+17%3A49%3A06%22%2C%22workCentreNumber%22%3A%22118%22%2C%22so%22%3A%221704-01%22%2C%22minutes%22%3A0%2C%22source%22%3A%22Scanner%22%2C%22active%22%3A1%2C%22operation_id%22%3A%22449%22%2C%22operation_type%22%3A%22queue%22%7D
- // Too big??
- $this->httpPost($url, $payload);
- protected function httpPost($url, $data)
- {
- $ch = curl_init(); //cURL handle
- curl_setopt_array($ch, [
- CURLOPT_HEADER => true,
- CURLOPT_POST => true,
- CURLOPT_POSTFIELDS => $payload,
- CURLOPT_RETURNTRANSFER => 1,
- CURLOPT_URL => $url,
- CURLOPT_HTTPHEADER => array('Expect:')
- ]);
- if ($result = curl_exec($ch)) {
- $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
- $response['header'] = substr($result, 0, $header_size);
- $response['content'] = substr($result, $header_size);
- $response['seconds'] = curl_getinfo($ch, CURLINFO_TOTAL_TIME);
- $response['http_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- $response['bytes'] = curl_getinfo($ch, CURLINFO_SIZE_DOWNLOAD);
- $response['bytes'] .= ' B (' . number_format(($response['bytes'] / 1024 / 1024), 3) . ' MB)';
- } else {
- die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
- }
- curl_close($ch);
- return $response;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement