HTTPWebRequest error handling vs PS Invoke-WebRequest

jordi79
Member Posts: 280
Hi,
In Powershell, if you use Invoke-WebRequest, and if there is an error, you will get the full error message.
e.g.
However, in NAV when I use HTTPWebRequest, I only get the error message:
I tried using Codeunit 1297 to return the webexception, and tried all the properties in websexception, but I could still not get the same detailed error I got in Powershell.
In Powershell, if you use Invoke-WebRequest, and if there is an error, you will get the full error message.
e.g.
Invoke-WebRequest : POST https://SOMEAPIURL with
My favourite address MODIFIED JN Street 100 JNStreet 200 Street 3 (if needed) Street 4 (if needed) Oslo 1234 NO true Mr. JN 93
: 400 Bad Request: This address already exists. To create a unique address, at least one of these fields must be changed: Name, Line 1, Line
2, City, State, Postal Code, Country/Region, Location Code, Attention, Address Owner Type, Local Tax Number, Parent Address.
At C:\ISS p2p GIL\httpwebrequest post addresses.ps1:10 char:1
+ Invoke-WebRequest `
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
However, in NAV when I use HTTPWebRequest, I only get the error message:
The remote server returned an error: (400) Bad Request.
I tried using Codeunit 1297 to return the webexception, and tried all the properties in websexception, but I could still not get the same detailed error I got in Powershell.
0
Best Answer
-
Try WebException.Response.GetResponseStream0
Answers
-
Try WebException.Response.GetResponseStream0
-
Hi Vaprog.
It works like charm.
Thanks
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions