Bonjour à tous,
Je viens vers vous avec un sérieux problème.
Voila je tente d'envoyer un fichier au format json a un serveur distant avec la fonction curl (methode post)
mais le problème est qu'il me retourne bad requeste (400) , pourtant j'ai bien mis les options necessaires a la fonction curl.
SVP! aidez moi.
le contenu du fichier json:
{"ordersRequest":{ "orders":{ "order":[{"comment":"zee",
"orderId":4461,
"status":"Cancelled"}]}}}
//le script
$headers = array(
"Accept:application/json",
"Content-type:application/json",
);
$data=array('fichier'=>'fichier.json');
/*initialisation de la session*/
$ch = curl_init();
// /*configuration des options*/
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
/*exécution de la session*/
$sCurlResponse = curl_exec($ch);
curl_close ($ch);
var_dump($sCurlResponse);
Voici le message d'erreur et les informations de l'entête http
HTTP/1.1 400 Bad Request
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 20 Dec 2013 11:26:18 GMT
Content-Length: 57
[{"message":"Input string was not in a correct format."}]
Merci d'avance pour votre aide.