Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

PowerShell HTTP 500 response error body

$
0
0

In PowerShell, I'm calling a SOAP web service and getting a HTTP 500 error at this line

 [System.Net.WebResponse]$resp=$webRequest.GetResponse()

and $_  error object returns:

 The remote server returned an error: (500) Internal Server Error.

How do I get full error details that is contained in the SOAP Fault String? (I do see it in Fiddler).

The ErrorDetails property is blank and I don't see how to get the SOAP fault string.

TypeName: System.Management.Automation.ErrorRecord

Name                  MemberType     Definition                                                                                                  
----                  ----------     ----------                                                                                                  
Equals                Method         bool Equals(System.Object obj)                                                                              
GetHashCode           Method         int GetHashCode()                                                                                           
GetObjectData         Method         void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.Strea...
GetType               Method         type GetType()                                                                                              
ToString              Method         string ToString()                                                                                           
CategoryInfo          Property       System.Management.Automation.ErrorCategoryInfo CategoryInfo {get;}                                          
ErrorDetails          Property       System.Management.Automation.ErrorDetails ErrorDetails {get;set;}                                           
Exception             Property       System.Exception Exception {get;}                                                                           
FullyQualifiedErrorId Property       string FullyQualifiedErrorId {get;}                                                                         
InvocationInfo        Property       System.Management.Automation.InvocationInfo InvocationInfo {get;}                                           
PipelineIterationInfo Property       System.Collections.ObjectModel.ReadOnlyCollection[int] PipelineIterationInfo {get;}                         
ScriptStackTrace      Property       string ScriptStackTrace {get;}                                                                              
TargetObject          Property       System.Object TargetObject {get;}                                                                           
PSMessageDetails      ScriptProperty System.Object PSMessageDetails {get=& { Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessag...

I already tried the below code in the Catch block but $ex.Reponse returns nothing.

catch[System.Net.WebException]  {

$ex=$_

if  ($ex-ne$null) {

$resp=$ex.Response;

$rs=$resp.GetResponseStream();

[System.IO.StreamReader]$sr=New-ObjectSystem.IO.StreamReader-argumentList$rs;

[string]$results=$sr.ReadToEnd();

return$results;

            }

else{

return$ex

            }

    }



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>