0

I have an xml document that needs to be uploaded to a url for processing by the webservice, I have limited resources so I'll have to use a powershell script for this task, ver 1. No, I cannot upgrade to 3 which I know has more tools for this type of job.

Basically I need to replicate this (Which works fine in linux)

curl -d @event1.xml URL -H 'Content-Type: text/xml'  -s

So far all I've been able to find is that I need to use System.Net.HttpWebRequest but using this is beyond me since I haven't been able to use it to get a response.

SO, is there a way to upload a text file using powershell? Or will I have to go about this another way completely?

1

1 Answer 1

2

I don't have a site to test with, but I guess you need something like this:

$req = New-Object System.Net.HttpWebRequest
$req.Method = "POST"
$req.ContentType = "text/xml"
$data = [System.IO.File]::ReadAllBytes("C:\test.xml")
$req.ContentLength = $data.Length
$reqstream = $req.GetRequestStream()
$reqstream.Write($data, 0, $data.Length)
$reqstream.Close()

If you need to catch the response, you will have to add that.

$res = $req.getresponse().getresponsestream() 

++

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.