pat2607 Posted August 9, 2017 Share Posted August 9, 2017 Bonjour, J'ai besoin de déclarer un USERAGENT dans cette requête. Depuis le changement d'hébergeur, les requête POST ne sont plus acceptée sans USERAGENT. Quelqu'un pourrait-il me dire la syntaxe pour pouvoir le faire? Merci de votre aide à tous. protected function executeRequest($url, $curl_params = array()) { $defaultParams = array( CURLOPT_HEADER => TRUE, CURLOPT_RETURNTRANSFER => TRUE, CURLINFO_HEADER_OUT => TRUE, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERPWD => $this->key.':', CURLOPT_HTTPHEADER => array( 'Expect:' ) ); $session = curl_init($url); $curl_options = array(); foreach ($defaultParams as $defkey => $defval) { if (isset($curl_params[$defkey])) $curl_options[$defkey] = $curl_params[$defkey]; else $curl_options[$defkey] = $defaultParams[$defkey]; } foreach ($curl_params as $defkey => $defval) if (!isset($curl_options[$defkey])) $curl_options[$defkey] = $curl_params[$defkey]; curl_setopt_array($session, $curl_options); $response = curl_exec($session); $index = strpos($response, "\r\n\r\n"); if ($index === false && $curl_params[CURLOPT_CUSTOMREQUEST] != 'HEAD') throw new PrestaShopWebserviceException('Bad HTTP response'); $header = substr($response, 0, $index); $body = substr($response, $index + 4); $headerArrayTmp = explode("\n", $header); $headerArray = array(); foreach ($headerArrayTmp as &$headerItem) { $tmp = explode(':', $headerItem); $tmp = array_map('trim', $tmp); if (count($tmp) == 2) $headerArray[$tmp[0]] = $tmp[1]; } if (array_key_exists('PSWS-Version', $headerArray)) { if ( version_compare(PrestaShopWebservice::psCompatibleVersionsMin, $headerArray['PSWS-Version']) == 1 || version_compare(PrestaShopWebservice::psCompatibleVersionsMax, $headerArray['PSWS-Version']) == -1 ) throw new PrestaShopWebserviceException('This library is not compatible with this version of PrestaShop. Please upgrade/downgrade this library'); } if ($this->debug) { $this->printDebug('HTTP REQUEST HEADER', curl_getinfo($session, CURLINFO_HEADER_OUT)); $this->printDebug('HTTP RESPONSE HEADER', $header); } $status_code = curl_getinfo($session, CURLINFO_HTTP_CODE); if ($status_code === 0) throw new PrestaShopWebserviceException('CURL Error: '.curl_error($session)); curl_close($session); if ($this->debug) { if ($curl_params[CURLOPT_CUSTOMREQUEST] == 'PUT' || $curl_params[CURLOPT_CUSTOMREQUEST] == 'POST') $this->printDebug('XML SENT', $curl_params[CURLOPT_POSTFIELDS]); if ($curl_params[CURLOPT_CUSTOMREQUEST] != 'DELETE' && $curl_params[CURLOPT_CUSTOMREQUEST] != 'HEAD') $this->printDebug('RETURN HTTP BODY', $body); } return array('status_code' => $status_code, 'response' => $body, 'header' => $header); } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now