@@ -49,6 +49,7 @@ Public Enum AvailableMethods
49
49
End Enum
50
50
Public Enum AvailableFormats
51
51
json
52
+ formurlencoded
52
53
End Enum
53
54
54
55
' --------------------------------------------- '
@@ -136,7 +137,7 @@ Public Property Get FormattedResource() As String
136
137
137
138
' Only load parameters to querystring if GET request (otherwise they are added to the body)
138
139
If Me.Method = httpGET Then
139
- FormattedResource = FormattedResource & RestHelpers.DictionariesToUrlEncodedString(Me.QuerystringParams , Me.Parameters )
140
+ FormattedResource = FormattedResource & RestHelpers.DictionariesToUrlEncodedString(Me.Parameters , Me.QuerystringParams )
140
141
Else
141
142
FormattedResource = FormattedResource & RestHelpers.DictionariesToUrlEncodedString(Me.QuerystringParams)
142
143
End If
@@ -147,24 +148,30 @@ End Property
147
148
Public Property Get Body() As String
148
149
' Add body if it's defined or parameters have been set and it is not a GET request
149
150
If Not pBody Is Nothing Or pBodyString <> "" Or (Me.Parameters.count > 0 And Me.Method <> httpGET) Then
150
- Select Case Me.Format
151
- ' (Currently only JSON is supported)
152
- Case Else
153
- If pBodyString <> "" Then
154
- If Me.Parameters.count > 0 And Me.Method <> httpGET Then
155
- Err.Raise vbObjectError + 1 , "RestRequest.Body" , "Unable to combine body string and parameters"
151
+ If pBodyString <> "" Then
152
+ If Me.Parameters.count > 0 And Me.Method <> httpGET Then
153
+ Err.Raise vbObjectError + 1 , "RestRequest.Body" , "Unable to combine body string and parameters"
154
+ Else
155
+ Body = pBodyString
156
+ End If
157
+ Else
158
+ Select Case Me.Format
159
+ Case AvailableFormats.formurlencoded
160
+ If Me.Method <> httpGET Then
161
+ ' Combine defined body and parameters and convert to JSON
162
+ Body = RestHelpers.DictionariesToUrlEncodedString(Me.Parameters, pBody)
156
163
Else
157
- Body = pBodyString
164
+ Body = RestHelpers.DictionariesToUrlEncodedString(pBody)
158
165
End If
159
- Else
166
+ Case AvailableFormats.json
160
167
If Me.Method <> httpGET Then
161
168
' Combine defined body and parameters and convert to JSON
162
- Body = RestHelpers.ConvertToJSON(CombineObjects(pBody, Me.Parameters))
169
+ Body = RestHelpers.ConvertToJSON(CombineObjects(Me.Parameters, pBody ))
163
170
Else
164
171
Body = RestHelpers.ConvertToJSON(pBody)
165
172
End If
166
- End If
167
- End Select
173
+ End Select
174
+ End If
168
175
End If
169
176
End Property
170
177
@@ -200,7 +207,9 @@ End Property
200
207
201
208
Public Property Get FormatName() As String
202
209
Select Case Me.Format
203
- Case Else
210
+ Case AvailableFormats.formurlencoded
211
+ FormatName = "form-urlencoded"
212
+ Case AvailableFormats.json
204
213
FormatName = "json"
205
214
End Select
206
215
End Property
@@ -210,12 +219,10 @@ Public Property Get ContentType() As String
210
219
ContentType = pContentType
211
220
Else
212
221
Select Case Me.Format
213
- Case Else
214
- If Me.Method <> httpGET And Me.Parameters.count > 0 Then
215
- ContentType = "application/x-www-form-urlencoded;charset=UTF-8"
216
- Else
217
- ContentType = "application/json"
218
- End If
222
+ Case AvailableFormats.formurlencoded
223
+ ContentType = "application/x-www-form-urlencoded;charset=UTF-8"
224
+ Case AvailableFormats.json
225
+ ContentType = "application/json"
219
226
End Select
220
227
End If
221
228
End Property
0 commit comments