Sunday, 15 March 2015

python - How to POST to URL in PowerShell? -



python - How to POST to URL in PowerShell? -

i have python script posts local file given url using requests:

import requests url = 'https://www.mywebsite.com/ext/ext/ext' info = "/users/me/documents/folder/folder/folder/test.json" open(data) test: headers = {'content-type': 'application/json', 'accept': 'text/plain'} r = requests.post(url, data=test, headers=headers)

i want exact same thing in powershell. have limited powershell scripting experience , other stack overflow posts seem verbose/involved (such this stack overflow answer). there short, easy way this? 'requests' equivalent powershell?

you want utilize invoke-webrequest (get raw request data) or invoke-restmethod (parses json, xml, etc. turns powershell obj).

for utilize case, invoke-webrequest:

$uri = 'https://www.mywebsite.com/ext/ext/ext' $data = get-content "test.json" $result = invoke-webrequest -uri $uri -body $data -contenttype 'application/json' -method post $result.rawcontent

python powershell

No comments:

Post a Comment