Quando eseguo la seguente dichiarazioneCome faccio ad avere il corpo di una richiesta Web che ha restituito 400 Bad Request da Invoke-RestMethod
Invoke-RestMethod "https://api.mysite.com/the/endpoint" `
-Body (ConvertTo-Json $data) `
-ContentType "application/json" `
-Headers $DefaultHttpHeaders `
-Method Post
l'endpoint restituisce 400 Bad Request
, che provoca PowerShell per mostrare la seguente non-così messaggio -helpful:
Invoke-WebRequest : The remote server returned an error: (400) Bad Request. At line:1 char:1 + Invoke-WebRequest "https://api.mysite.com/the/endpoint" -Body ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Come faccio ad avere il corpo della risposta, che mi potrebbe dire cosa non andava con la richiesta che ho inviato?
Forse il server dovrebbe essere fissata: '200 OK' '* o * 400 Bad request'. –
@LutzHorn: In questo caso so che è la mia chiamata API che non è corretta. Non so esattamente * perché *. –
Siamo spiacenti, la '200 Richiesta non valida 'era un errore di battitura; dovrebbe essere '400 Bad Request'. La dichiarazione nel mio codice attuale non ha interruzioni di linea, come affermato. –