MugunthKumar/MKNetworkKit — Issue #68: response issue
Author: paul321
Created: 2012-03-07 12:52:57+00:00
State: open

Hi

i have the following piece of code that requests a page parses a table and extracts an element from the table, also that element has a url that needs to be queried to get an image, so the code has 2 operations one inside the other but the problem is that i get a lot of empty responses i dont know why and i dont think it's from the server because when i debug it and see the if body1==nil there in the headers it says content length > 0

here is the code

MKNetworkOperation *op = [self operationWithURLString:url params:fields];

[op onCompletion:^(MKNetworkOperation *operation) {
HTMLParser *parser = [[HTMLParser alloc] initWithString:op.responseString error:nil];
HTMLNode *body = [parser body];

HTMLNode *dataTable = [body findChildWithAttribute:@"class" matchingName:@"striped full" allowPartial:YES];
NSArray *rows = [dataTable findChildTags:@"tr"];

for (HTMLNode *trNode in rows) {
NSArray *cells = [trNode findChildTags:@"td"];
if(cells != nil && [cells count] > 0) {
Image *image = [[Image alloc] init];
HTMLNode *urlEl = [nameEl findChildTag:@"a"];

NSString *imageDetailsUrl = [urlEl getAttributeNamed:@"href"];

MKNetworkOperation *op1 = [self operationWithURLString:[host stringByAppendingString:imageDetailsUrl] params:nil];
[op1 onCompletion:^(MKNetworkOperation *operation1) {
HTMLParser *parser1 = [[HTMLParser alloc] initWithString:[op1 responseString] error:nil];
HTMLNode *body1 = [parser1 body];

NSLog(@"%lu", [[op1 responseString] length]);

if (body1 == nil) {
NSLog(@"nil.....");
NSDictionary *a = [[operation1 readonlyResponse] allHeaderFields];
}

HTMLNode *imageEl = [body1 findChildWithAttribute:@"id" matchingName:@"imagedetail_main_image" allowPartial:YES];
image.url = [imageEl getAttributeNamed:@"src"];

completionBlock(images);
} onError:^(NSError *error) {
DLog(@"%@", error);
}];

[images addObject:image];

[self enqueueOperation:op1];

}
}

completionBlock(images);

} onError:^(NSError *error) {
DLog(@"%@", error);
}];

[self enqueueOperation:op];

thanks