Calling a URL via POST method with JSON object, but using Powershell -


i attempting call specific url via post method, json object passed post form parameter. json object needs passed this:

obj={ "login":"[username here]", "pword":"[password here]" } 

with powershell, attempting create hash , convert json, connect invoke-restmethod command.

$hash = @{  login = "username";              pword = "password"             }  $obj = $hash | convertto-json invoke-restmethod 'https://website.com/login' -method post -body $obj -contenttype 'application/x-www-form-urlencoded' 

however, returns error. double-checking documentation, notes form parameter name must obj, web services looks parameter called obj, takes string value, converts json object retrieve internal values.

this getting little stuck. how can specific form parameter name when using powershell?

the form you've presented:

obj={ "login":"[username here]", "pword":"[password here]" } 

appears invalid json. so.. you'd have fudge it:

$hash = @{  login = "username";              pword = "password"             }  $obj = $hash | convertto-json $obj = 'obj=' + $obj invoke-restmethod 'https://website.com/login' -method post -body $obj -contenttype 'application/x-www-form-urlencoded' 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo