execute_post_now.ps1 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Script PowerShell pour exécuter la requête POST
  2. Write-Host "🚀 Exécution de la requête POST_userV2.php" -ForegroundColor Cyan
  3. Write-Host ""
  4. # Chemin du fichier JSON
  5. $jsonFile = Join-Path $PSScriptRoot "post_user_request.json"
  6. $url = "http://localhost:8000/user/user/POST_userV2.php"
  7. # Démarrer le serveur PHP en arrière-plan
  8. Write-Host "📡 Démarrage du serveur PHP sur localhost:8000..." -ForegroundColor Yellow
  9. $serverProcess = Start-Process -NoNewWindow -PassThru php -ArgumentList "-S","localhost:8000","-t","$PSScriptRoot\..\api"
  10. # Attendre que le serveur démarre
  11. Start-Sleep -Seconds 3
  12. Write-Host "✅ Serveur démarré" -ForegroundColor Green
  13. Write-Host ""
  14. # Envoyer la requête POST
  15. Write-Host "📤 Envoi de la requête POST..." -ForegroundColor Yellow
  16. Write-Host "📄 Fichier: $jsonFile" -ForegroundColor Gray
  17. Write-Host "🌐 URL: $url" -ForegroundColor Gray
  18. Write-Host ""
  19. try {
  20. $jsonContent = Get-Content $jsonFile -Raw
  21. $response = Invoke-RestMethod -Uri $url -Method Post -Body $jsonContent -ContentType "application/json" -ErrorAction Stop
  22. Write-Host "✅ Succès!" -ForegroundColor Green
  23. Write-Host ""
  24. Write-Host "📄 Réponse:" -ForegroundColor Cyan
  25. $response | ConvertTo-Json -Depth 10
  26. } catch {
  27. Write-Host "❌ Erreur:" -ForegroundColor Red
  28. Write-Host $_.Exception.Message -ForegroundColor Red
  29. if ($_.ErrorDetails) {
  30. Write-Host $_.ErrorDetails.Message -ForegroundColor Red
  31. }
  32. Write-Host ""
  33. Write-Host "💡 Essayez avec curl:" -ForegroundColor Yellow
  34. Write-Host "curl -X POST `"$url`" -H `"Content-Type: application/json`" -d `"@$jsonFile`""
  35. }
  36. Write-Host ""
  37. Write-Host "🛑 Arrêt du serveur PHP..." -ForegroundColor Yellow
  38. Stop-Process -Id $serverProcess.Id -Force -ErrorAction SilentlyContinue
  39. Write-Host "✅ Serveur arrêté" -ForegroundColor Green