Powershell - POST XML on a webservice Not working

Tal 26 Reputation points
2021-08-23T03:30:35.73+00:00

Greetings,
I have a simple POST to a webservice to make through PS.
I've done many in my life, however I just cant figure out what is the problem with this one. (I've also tried in VBs - getting same result)

I have an XML with content which I should POST to the webservice, using SOAPUI everything works perfectly, however when I use POSTMAN I can server internal error (there are no special headers nor authentication)

I tried the following when parsing the XML:

$Parameters = @'
<XML Stuff>
'@

and then I tried the following:
Option 1:

$Url = <http://My URL>?wsdl
also tried without ?wsdl
$Url = <http://My URL>

and then:
Invoke-webrequest -Uri $Url -Method POST -Body $Parameters -ContentType "text/xml" (also tried "application/xml")

or:
$http_request = new-object -comobject Msxml2.XMLHTTP
$http_request.open('POST', $Url, $false)
$http_request.SetRequestHeader("Content-type", "text/xml")
$http_request.SetRequestHeader("Content-Length", $Parameters.Length)
$http_request.SetRequestHeader("Connection", "close") #Also Tried without
$http_request.send($Parameters)
$http_request.statusText
$http_request.ResponseText

ending up getting same result which is server internal error... why?
I've also tried to take $Parameters and export it and paste it into SOAPUI and see if something happened to the XML but everything seems to be working just fine.

any clue?

Thanks in advance.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,576 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 39,721 Reputation points
    2021-08-25T07:37:29.983+00:00

    Hello tal,

    Send XML requests with the raw data type, then set the Content-Type to text/xml.

    Do follow the below steps

    1. After creating a request, use the dropdown to change the request type to POST.

    2.Open the Body tab and check the data type for raw.

    3.Open the Content-Type selection box that appears to the right and select either XML (application/xml) or XML (text/xml)

    1. Enter your raw XML data into the input field below

    5.Click Send to submit your XML Request to the specified server.

    Hope this Answers all your queries , if not please do repost back .
    If an Answer is helpful, please click "Accept Answer" and upvote it : )

    Regards,

    jainth S


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.