| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- # Script PowerShell pour exécuter la requête POST
- Write-Host "🚀 Exécution de la requête POST_userV2.php" -ForegroundColor Cyan
- Write-Host ""
- # Chemin du fichier JSON
- $jsonFile = Join-Path $PSScriptRoot "post_user_request.json"
- $url = "http://localhost:8000/user/user/POST_userV2.php"
- # Démarrer le serveur PHP en arrière-plan
- Write-Host "📡 Démarrage du serveur PHP sur localhost:8000..." -ForegroundColor Yellow
- $serverProcess = Start-Process -NoNewWindow -PassThru php -ArgumentList "-S","localhost:8000","-t","$PSScriptRoot\..\api"
- # Attendre que le serveur démarre
- Start-Sleep -Seconds 3
- Write-Host "✅ Serveur démarré" -ForegroundColor Green
- Write-Host ""
- # Envoyer la requête POST
- Write-Host "📤 Envoi de la requête POST..." -ForegroundColor Yellow
- Write-Host "📄 Fichier: $jsonFile" -ForegroundColor Gray
- Write-Host "🌐 URL: $url" -ForegroundColor Gray
- Write-Host ""
- try {
- $jsonContent = Get-Content $jsonFile -Raw
- $response = Invoke-RestMethod -Uri $url -Method Post -Body $jsonContent -ContentType "application/json" -ErrorAction Stop
-
- Write-Host "✅ Succès!" -ForegroundColor Green
- Write-Host ""
- Write-Host "📄 Réponse:" -ForegroundColor Cyan
- $response | ConvertTo-Json -Depth 10
- } catch {
- Write-Host "❌ Erreur:" -ForegroundColor Red
- Write-Host $_.Exception.Message -ForegroundColor Red
- if ($_.ErrorDetails) {
- Write-Host $_.ErrorDetails.Message -ForegroundColor Red
- }
- Write-Host ""
- Write-Host "💡 Essayez avec curl:" -ForegroundColor Yellow
- Write-Host "curl -X POST `"$url`" -H `"Content-Type: application/json`" -d `"@$jsonFile`""
- }
- Write-Host ""
- Write-Host "🛑 Arrêt du serveur PHP..." -ForegroundColor Yellow
- Stop-Process -Id $serverProcess.Id -Force -ErrorAction SilentlyContinue
- Write-Host "✅ Serveur arrêté" -ForegroundColor Green
|