Curl qui donne un fatal error mais sans rien de plus ...

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : Curl qui donne un fatal error mais sans rien de plus ...

Re: Curl qui donne un fatal error mais sans rien de plus ...

par ErwinB » 23 mars 2013, 11:58

Bonjour,

Peut-être un conseil qui pourrait t'aider, modifier ton bloc try/catch de la façon suivante :
try{
	$curl_errno = null;
	$curl_error = null;
	$response 	= curl_exec($session);
	$curl_errno = curl_errno( $response );
	$curl_error = curl_error( $response );
	
	if( $curl_errno )
	{
		// Do something
	}
}
catch (\Exception $e){
	throw new \Exception('Mauvais paramètres envoyés.');
}
Tu pourras peut-être plus facilement savoir ce qui ne va pas dans ta requête Curl à cet endroit. D'autant qu'à ma connaissance (mais je peux me tromper là-dessus), Curl ne lance pas d'Exceptions, tu devrais peut-être en lancer si Curl te renvoie une erreur ("Do something").

Edit : tu peux également regarder du côté du paramètre CURLOPT_VERBOSE. Ceci dit, le Fatal Error peut aussi provenir de l'API en face, si le flux XML envoyé ne valide pas de ce côté.

Curl qui donne un fatal error mais sans rien de plus ...

par Amelie » 22 mars 2013, 11:36

Bonjour,

J'envoie des informations à l'APi Prestashop via CURL.
Le souci c'est que pour une certaine requete, Curl me renvoit "Fatal error" mais sans aucune autre info.

Voici le code renvoyé :
HTTP RESPONSE HEADER

HTTP/1.1 200 OK
Date: Fri, 22 Mar 2013 09:35:42 GMT
Server: Apache/2.2.16 (Debian)
X-Powered-By: PHP/5.3.3-7+squeeze14
Set-Cookie: 3f99a2f33f7744ef0eca694ec6b1a644=s9d7eoHKLJNpxgxpF77%2BJn21huhgfjg1pt1EeG1eWzcIbcKpg0RsOylYsEG64biER1YgHAaDrhYV2CK7sr4zOA%3D%3D000059; expires=Thu, 11-Apr-2013 09:35:42 GMT; path=/; domain=prestashop.pixtory-redmine.reseaux.info; httponly
Vary: Authorization,Host
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

XML SENT

xml=<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<order>
<id></id>
<id_address_delivery>23</id_address_delivery>
<id_address_invoice>23</id_address_invoice>
<id_cart>4</id_cart>
<id_currency>2</id_currency>
<id_lang>5</id_lang>
<id_customer>24</id_customer>
<id_carrier>8</id_carrier>
<current_state>1</current_state>
<module>cheque</module>
<invoice_number>1</invoice_number>
<invoice_date>2013-03-22 09:45:22</invoice_date>
<delivery_number></delivery_number>
<delivery_date></delivery_date>
<valid>0</valid>
<date_add></date_add>
<date_upd></date_upd>
<id_shop_group>1</id_shop_group>
<id_shop>1</id_shop>
<secure_key></secure_key>
<payment>Chèque</payment>
<recyclable>0</recyclable>
<gift>0</gift>
<gift_message></gift_message>
<total_discounts>0.00</total_discounts>
<total_discounts_tax_incl>0.00</total_discounts_tax_incl>
<total_discounts_tax_excl>0.00</total_discounts_tax_excl>
<total_paid>45.90</total_paid>
<total_paid_tax_incl>45.90</total_paid_tax_incl>
<total_paid_tax_excl>36.9</total_paid_tax_excl>
<total_paid_real>45.90</total_paid_real>
<total_products>45.90</total_products>
<total_products_wt>45.90</total_products_wt>
<total_shipping>10.00</total_shipping>
<total_shipping_tax_incl>10.00</total_shipping_tax_incl>
<total_shipping_tax_excl>10.00</total_shipping_tax_excl>
<carrier_tax_rate>0.000</carrier_tax_rate>
<total_wrapping>0.00</total_wrapping>
<total_wrapping_tax_incl>0.00</total_wrapping_tax_incl>
<total_wrapping_tax_excl>0.00</total_wrapping_tax_excl>
<shipping_number></shipping_number>
<conversion_rate>1.000000</conversion_rate>
<reference>PZBSOLJVV</reference>

<associations><order_rows><order_row><product_id>9</product_id><product_quantity>1</product_quantity><product_name>Votre impression Multi-photo</product_name><product_price>35.9</product_price></order_row></order_rows></associations></order>
</prestashop>

RETURN HTTP BODY

Fatal error
Et la fonction qui gère l'exécution :

Code : Tout sélectionner

protected function executeRequest($url, $curl_params = array()) { $defaultParams = array( CURLOPT_HEADER => TRUE, CURLOPT_RETURNTRANSFER => TRUE, CURLINFO_HEADER_OUT => TRUE, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_ENCODING=> 'UTF-8', 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); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); try{ $response = curl_exec($session); } catch (\Exception $e){ throw new \Exception('Mauvais paramètres envoyés.'); } $index = strpos($response, "\r\n\r\n"); if ($index === false && $curl_params[CURLOPT_CUSTOMREQUEST] != 'HEAD') throw new PrestaShopWebserviceException('Mauvaise requête.'); $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 \Exception('Librairie incompatible avec cette version de Prestashop.'); } 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 \Exception('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); }
Des idées ? merci :priere: