| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- /**
- * Script pour exécuter une requête POST_userV2.php de test
- */
- // Charger le JSON de la requête
- $json_file = __DIR__ . '/post_user_request.json';
- $post_data = json_decode(file_get_contents($json_file), true);
- if ($post_data === null) {
- die("❌ Erreur: Impossible de charger le fichier post_user_request.json\n");
- }
- // Générer un nouveau login unique pour éviter les conflits
- $timestamp = time();
- $post_data['login'] = "test.user.{$timestamp}@sipa-automobiles.fr";
- $post_data['mail'] = $post_data['login'];
- $post_data['employeeNumber'] = "TEST{$timestamp}";
- $post_data['dtContractStart'] = date('Y-m-d\TH:i:s', strtotime('+1 day'));
- $post_data['seniorityDate'] = $post_data['dtContractStart'];
- echo "🚀 Exécution de la requête POST_userV2.php...\n\n";
- echo "📋 Données envoyées:\n";
- echo json_encode($post_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n";
- // Simuler une requête POST en appelant directement le script PHP
- $_SERVER['REQUEST_METHOD'] = 'POST';
- $_GET = [];
- $_POST = [];
- // Capturer le body de la requête
- $json_body = json_encode($post_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
- // Créer un fichier temporaire pour simuler php://input
- $temp_file = tempnam(sys_get_temp_dir(), 'php_input_');
- file_put_contents($temp_file, $json_body);
- // Rediriger php://input vers notre fichier temporaire
- // Note: On ne peut pas vraiment rediriger php://input, donc on va utiliser curl
- echo "📡 Envoi de la requête via curl...\n\n";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'http://localhost/api/user/user/POST_userV2.php');
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $json_body);
- curl_setopt($ch, CURLOPT_HTTPHEADER, [
- 'Content-Type: application/json',
- 'Content-Length: ' . strlen($json_body)
- ]);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_VERBOSE, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- $response = curl_exec($ch);
- $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- $curl_error = curl_error($ch);
- curl_close($ch);
- echo "📊 Résultat:\n";
- echo "HTTP Code: {$http_code}\n\n";
- if ($curl_error) {
- echo "❌ Erreur cURL: {$curl_error}\n";
- echo "\n💡 Astuce: Assurez-vous que votre serveur web local est démarré (Apache/Nginx)\n";
- echo " et que l'URL http://localhost/api/user/user/POST_userV2.php est accessible.\n";
- } else {
- echo "📄 Réponse:\n";
-
- // Essayer de formater la réponse JSON
- $response_json = json_decode($response, true);
- if ($response_json !== null) {
- echo json_encode($response_json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n";
- } else {
- echo $response . "\n";
- }
-
- if ($http_code === 200 || $http_code === 201) {
- echo "\n✅ Utilisateur créé avec succès!\n";
- } else {
- echo "\n⚠️ La requête a retourné le code HTTP {$http_code}\n";
- }
- }
- // Nettoyer
- if (file_exists($temp_file)) {
- unlink($temp_file);
- }
|