Skip to content

Commit

Permalink
Implementing post parameter work for any methods. PUT and POST use fi…
Browse files Browse the repository at this point in the history
…rst if no other parameter are specified
  • Loading branch information
Yuru Taustahuzau committed Aug 10, 2014
1 parent 2287181 commit d15468a
Showing 1 changed file with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,25 +283,19 @@ - (void)prepareDownloadBlock {
- (NSMutableURLRequest *)requestForUrl:(NSURL * const)anUrl withMethod:(NSString * const)method withBody:(NSData *)httpBody values:(NSDictionary *)values {
NSData *body = httpBody;

if ([_callAttribute.method isEqualToString:@"POST"] || [_callAttribute.method isEqualToString:@"PUT"]) {
if (_callAttribute.postParameter != (int)NSNotFound && !httpBody.length) {
id bodyObject = values[[NSString stringWithFormat:@"%d", _callAttribute.postParameter]];
body = [self dataFromParameter:bodyObject];
}
else {
if ([body length] == 0) {
id firstParameter = values[@"0"];
if (firstParameter) { // Checking first parameter of web service call method
body = [self dataFromParameter:firstParameter];
}
}
else if (_callAttribute.postParameter != (int)NSNotFound) {
RFWSLogWarn(@"Web service method %@ specifies postParameter, but has NSData or RFFormData variable in parameters and use it instead", method);
if (_callAttribute.postParameter != (int)NSNotFound) {
id bodyObject = values[[NSString stringWithFormat:@"%d", _callAttribute.postParameter]];
body = [self dataFromParameter:bodyObject];
}
else if ([_callAttribute.method isEqualToString:@"POST"] || [_callAttribute.method isEqualToString:@"PUT"]) {
if ([body length] == 0) {
id firstParameter = values[@"0"];
if (firstParameter) { // Checking first parameter of web service call method
body = [self dataFromParameter:firstParameter];
}
}
}


NSMutableURLRequest * const request = [NSMutableURLRequest requestWithURL:anUrl];
request.HTTPMethod = method;
request.HTTPBody = body;
Expand Down Expand Up @@ -371,6 +365,10 @@ - (NSData *)dataFromParameter:(id)parameter {
data = [parameter dataUsingEncoding:NSUTF8StringEncoding];
}

if ([parameter isKindOfClass:[NSData class]]) {
data = parameter;
}

return data;
}

Expand Down

0 comments on commit d15468a

Please sign in to comment.