JSON formatted reply - Need help with response information
i've got script interacts jira create , updates issues(tickets). during interaction, jira sends response each time. just values change each new issue.
{"id":"315199","key":"itim-20728","self":"http://ourjiratestserver:8180/rest/ap
i/2/issue/315199"}
the part of code see is:
$b64 = convertto-base64($username + ":" + $password);$auth = "basic " + $b64;
$webrequest = [system.net.webrequest]::create($target+"/rest/api/2/issue/")
$webrequest.contenttype = "application/json"
$bodystr = [system.text.encoding]::utf8.getbytes($body)
$webrequest.contentlength = $bodystr.length
$webrequest.servicepoint.expect100continue = $false
$webrequest.headers.add("authorization", $auth);
$webrequest.preauthenticate = $true
$webrequest.method = "post"
$requeststream = $webrequest.getrequeststream()
$requeststream.write($bodystr, 0, $bodystr.length)
$requeststream.close()
[system.net.webresponse] $resp = $webrequest.getresponse()
$rs = $resp.getresponsestream()
[system.io.streamreader] $sr = new-object system.io.streamreader -argumentlist $rs
[string] $results = $sr.readtoend()
write-output $results
}
catch [system.net.webexception]{
if ($_.exception -ne $null -and $_.exception.response -ne $null) {
$errorresult = $_.exception.response.getresponsestream()
$errortext = (new-object system.io.streamreader($errorresult)).readtoend()
write-warning "the remote server response: $errortext"
write-output $_.exception.response.statuscode
} else {
throw $_
}
}
how can take response , pull url path out of , place variable?
thanks
just convert it:
ps d:\scripts> $a = '{"id":"315199","key":"itim-20728","self":"http://ourjiratestserver:8180/rest/api/2/issue/315199"}' ps d:\scripts> ($a | convertfrom-json).self http://ourjiratestserver:8180/rest/api/2/issue/315199easier use "invoke-webrequest" of work you.
\_(ツ)_/
Windows Server > Windows PowerShell
Comments
Post a Comment