protected function getToken($cache_token = false) { //create array of data to be posted $post_data = []; $post_data['UserName'] = $this->user_name; //You should add your test user $post_data['UserPassword'] = $this->user_password; //You should add your test password $post_data['UserContractCode'] = $this->user_contract_code; //You should add your test account/contract //traverse array and prepare data for posting (key1=value1) $post_items = []; foreach ($post_data as $key => $value) { $post_items[] = $key . '=' . $value; } //create the final string to be posted using implode() $post_string = implode('&', $post_items); //create cURL connection $curl_connection = curl_init('https://api.winkas.net/api/Authentication/Authenticate'); // Store received headers in temporary memory file, remember sent headers $fh_header = fopen('php://temp', 'w+'); curl_setopt($curl_connection, CURLOPT_WRITEHEADER, $fh_header); curl_setopt($curl_connection, CURLINFO_HEADER_OUT, true); //set options curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($curl_connection, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'); curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); //set data to be posted curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); //perform our request $result = curl_exec($curl_connection); // Grab the headers //$sent_headers = curl_getinfo($curl_connection, CURLINFO_HEADER_OUT); rewind($fh_header); $received_headers = stream_get_contents($fh_header); fclose($fh_header); // Retrieve the HTTP response code $response_code = (int) curl_getinfo($curl_connection, CURLINFO_HTTP_CODE); if (!empty($curl_connection)) { curl_close($curl_connection); } $response = new Response($response_code, [], $received_headers, $result); $status = $response->httpStatus(); if ($status == 200) { $data = $response->asObject(); $this->token = $data->WinKasData->CurrentToken; } else { throw new Exception('Authentication failed'); } }