@@ -225,18 +225,34 @@ - (void)applyParameters:(NSDictionary *)parameters onRequest:(NSMutableURLReques
225
225
&& [httpMethod caseInsensitiveCompare: @" PUT" ] != NSOrderedSame) {
226
226
aRequest.URL = [aRequest.URL nxoauth2_URLByAddingParameters: parameters];
227
227
} else {
228
- NSInputStream *postBodyStream = [[NXOAuth2PostBodyStream alloc ] initWithParameters: parameters];
229
228
230
- NSString *contentType = [NSString stringWithFormat: @" multipart/form-data; boundary=%@ " , [(NXOAuth2PostBodyStream *)postBodyStream boundary ]];
231
- NSString *contentLength = [NSString stringWithFormat: @" %lld " , [(NXOAuth2PostBodyStream *)postBodyStream length ]];
232
- [aRequest setValue: contentType forHTTPHeaderField: @" Content-Type" ];
233
- [aRequest setValue: contentLength forHTTPHeaderField: @" Content-Length" ];
229
+ NSString *contentType = [aRequest valueForHTTPHeaderField: @" Content-Type" ];
234
230
235
- [aRequest setHTTPBodyStream: postBodyStream];
231
+ if (!contentType || [contentType isEqualToString: @" multipart/form-data" ]) {
232
+
233
+ // sends the POST/PUT request as multipart/form-data as default
234
+
235
+ NSInputStream *postBodyStream = [[NXOAuth2PostBodyStream alloc ] initWithParameters: parameters];
236
+
237
+ contentType = [NSString stringWithFormat: @" multipart/form-data; boundary=%@ " ,[(NXOAuth2PostBodyStream *)postBodyStream boundary ]];
238
+ NSString *contentLength = [NSString stringWithFormat: @" %lld " , [(NXOAuth2PostBodyStream *)postBodyStream length ]];
239
+ [aRequest setValue: contentType forHTTPHeaderField: @" Content-Type" ];
240
+ [aRequest setValue: contentLength forHTTPHeaderField: @" Content-Length" ];
241
+
242
+ [aRequest setHTTPBodyStream: postBodyStream];
243
+
244
+ }else if ([contentType isEqualToString: @" application/x-www-form-urlencoded" ]) {
245
+
246
+ // sends the POST/PUT request as application/x-www-form-urlencoded
247
+
248
+ NSString *query = [[aRequest.URL nxoauth2_URLByAddingParameters: parameters] query ];
249
+ [aRequest setHTTPBody: [query dataUsingEncoding: NSUTF8StringEncoding]];
250
+
251
+ }
252
+
236
253
}
237
254
}
238
255
239
-
240
256
- (BOOL )trustsAuthenticationChallenge : (NSURLAuthenticationChallenge *)challenge
241
257
forHostname : (NSString *)hostname
242
258
withTrustMode : (NXOAuth2TrustMode)trustMode ;
0 commit comments