@@ -58,18 +58,21 @@ function Invoke-Method {
58
58
Throw $exception
59
59
}
60
60
61
- # pass input to local variable
62
- # this allows to use the PSBoundParameters for recursion
63
- $_headers = $Headers
64
-
65
61
# Add Basic Authentication to Header
66
62
$SecureCreds = [System.Convert ]::ToBase64String([System.Text.Encoding ]::UTF8.GetBytes(
67
63
$ (' {0}:{1}' -f $Credential.UserName , $Credential.GetNetworkCredential ().Password)
68
64
))
69
- $_headers += @ {
70
- " Authorization" = " Basic $ ( $SecureCreds ) "
71
- ' Content-Type' = ' application/json; charset=utf-8'
65
+ $_headers = @ {
66
+ " Accept" = " application/json"
67
+ " Accept-Charset" = " utf-8"
68
+ " Authorization" = " Basic $ ( $SecureCreds ) "
69
+ " Content-Type" = " application/json; charset=utf-8"
72
70
}
71
+
72
+ # Append the Headers passed into the local variable _headers
73
+ # the variable used for the headers must be different from the parameter to allow
74
+ # the use of PSBoundParameters for recursion
75
+ $Headers.Keys.foreach ( {$_headers [$_ ] = $Headers [$_ ]})
73
76
}
74
77
75
78
Process {
@@ -84,6 +87,10 @@ function Invoke-Method {
84
87
$GetParameters = $null
85
88
}
86
89
90
+ # load DefaultParameters for Invoke-WebRequest
91
+ # as the global PSDefaultParameterValues is not used
92
+ $PSDefaultParameterValues = $global :PSDefaultParameterValues
93
+
87
94
# set mandatory parameters
88
95
$splatParameters = @ {
89
96
Uri = $URi
@@ -97,11 +104,6 @@ function Invoke-Method {
97
104
# http://stackoverflow.com/questions/15290185/invoke-webrequest-issue-with-special-characters-in-json
98
105
if ($Body ) {$splatParameters [" Body" ] = [System.Text.Encoding ]::UTF8.GetBytes($Body )}
99
106
100
- # load DefaultParameters for Invoke-WebRequest
101
- # as the global PSDefaultParameterValues is not used
102
- # TODO: find out why PSJira doesn't need this
103
- $script :PSDefaultParameterValues = $global :PSDefaultParameterValues
104
-
105
107
# Invoke the API
106
108
try {
107
109
Write-Verbose " [$ ( $MyInvocation.MyCommand.Name ) ] Invoking method $Method to URI $URi "
@@ -118,11 +120,13 @@ function Invoke-Method {
118
120
# Test HEADERS if Confluence requires a CAPTCHA
119
121
$tokenRequiresCaptcha = " AUTHENTICATION_DENIED"
120
122
$headerRequiresCaptcha = " X-Seraph-LoginReason"
121
- if (
122
- $webResponse.Headers [$headerRequiresCaptcha ] -and
123
- ($webResponse.Headers [$headerRequiresCaptcha ] -split " ," ) -contains $tokenRequiresCaptcha
124
- ) {
125
- Write-Warning " Confluence requires you to log on to the website before continuing for security reasons."
123
+ If ($webResponse.Headers ) {
124
+ if (
125
+ $webResponse.Headers [$headerRequiresCaptcha ] -and
126
+ ($webResponse.Headers [$headerRequiresCaptcha ] -split " ," ) -contains $tokenRequiresCaptcha
127
+ ) {
128
+ Write-Warning " Confluence requires you to log on to the website before continuing for security reasons."
129
+ }
126
130
}
127
131
}
128
132
@@ -154,7 +158,7 @@ function Invoke-Method {
154
158
else {
155
159
if ($webResponse.Content ) {
156
160
# API returned a Content: lets work wit it
157
- $response = ConvertFrom-Json - InputObject $webResponse.Content
161
+ $response = ConvertFrom-Json ([ Text.Encoding ]::UTF8.GetString( $webResponse.RawContentStream.ToArray ()))
158
162
159
163
if ($null -ne $response.errors ) {
160
164
Write-Verbose " [$ ( $MyInvocation.MyCommand.Name ) ] An error response was received from; resolving"
@@ -192,8 +196,8 @@ function Invoke-Method {
192
196
193
197
# Self-Invoke function for recursion
194
198
$parameters = @ {
195
- URi = " {0}{1}" -f $response._links.base , $response._links.next
196
- Method = $Method
199
+ URi = " {0}{1}" -f $response._links.base , $response._links.next
200
+ Method = $Method
197
201
Credential = $Credential
198
202
}
199
203
if ($Body ) {$parameters [" Body" ] = $Body }
0 commit comments