@@ -85,6 +85,7 @@ public async Task MultipartFormData() {
85
85
AddParameters ( request ) ;
86
86
87
87
string boundary = null ;
88
+
88
89
request . OnBeforeRequest = http => {
89
90
boundary = ( ( MultipartFormDataContent ) http . Content ) ! . GetFormBoundary ( ) ;
90
91
return default ;
@@ -110,6 +111,7 @@ public async Task MultipartFormData_HasDefaultContentType() {
110
111
request . AddParameter ( new BodyParameter ( "controlName" , "test" , "application/json" ) ) ;
111
112
112
113
string boundary = null ;
114
+
113
115
request . OnBeforeRequest = http => {
114
116
boundary = ( ( MultipartFormDataContent ) http . Content ) ! . GetFormBoundary ( ) ;
115
117
return default ;
@@ -139,6 +141,7 @@ public async Task MultipartFormData_WithCustomContentType() {
139
141
request . AddParameter ( new BodyParameter ( "controlName" , "test" , "application/json" ) ) ;
140
142
141
143
string boundary = null ;
144
+
142
145
request . OnBeforeRequest = http => {
143
146
boundary = ( ( MultipartFormDataContent ) http . Content ) ! . GetFormBoundary ( ) ;
144
147
return default ;
@@ -165,6 +168,7 @@ public async Task MultipartFormData_WithParameterAndFile_Async() {
165
168
request . AddParameter ( new BodyParameter ( "controlName" , "test" , "application/json" ) ) ;
166
169
167
170
string boundary = null ;
171
+
168
172
request . OnBeforeRequest = http => {
169
173
boundary = ( ( MultipartFormDataContent ) http . Content ) ! . GetFormBoundary ( ) ;
170
174
return default ;
@@ -180,21 +184,21 @@ public async Task MultipartFormData_WithParameterAndFile_Async() {
180
184
[ Fact ]
181
185
public async Task MultipartFormDataWithBoundaryOverride ( ) {
182
186
var request = new RestRequest ( "/" , Method . Post ) {
183
- AlwaysMultipartFormData = true ,
187
+ AlwaysMultipartFormData = true ,
184
188
FormatMultipartContentType = ( ct , b ) => $ "{ ct } ; boundary=--------{ b } "
185
189
} ;
186
190
187
191
AddParameters ( request ) ;
188
192
189
193
HttpContent content = null ;
190
- var boundary = "" ;
194
+ var boundary = "" ;
191
195
192
196
request . OnBeforeRequest = http => {
193
197
content = http . Content ;
194
198
boundary = ( ( MultipartFormDataContent ) http . Content ) ! . GetFormBoundary ( ) ;
195
199
return default ;
196
200
} ;
197
-
201
+
198
202
await _client . ExecuteAsync ( request ) ;
199
203
200
204
var contentType = content . Headers . ContentType ! . ToString ( ) ;
@@ -219,4 +223,21 @@ public async Task MultipartFormDataAsync() {
219
223
220
224
response . Content . Should ( ) . Be ( expected ) ;
221
225
}
226
+
227
+ [ Fact ]
228
+ public async Task ShouldHaveJsonContentType ( ) {
229
+ var jsonData = new {
230
+ Company = "Microsoft" ,
231
+ ZipCode = "LS339" ,
232
+ Country = "USA"
233
+ } ;
234
+
235
+ var request = new RestRequest {
236
+ Method = Method . Post ,
237
+ AlwaysMultipartFormData = true
238
+ } ;
239
+ request . AddJsonBody ( jsonData ) ;
240
+
241
+ var response = await _client . ExecuteAsync ( request ) ;
242
+ }
222
243
}
0 commit comments