AFNetworking 2.0 - Help getting Response Object from craigslist RSS page

512 Views Asked by At

I am completely new to Networking and using AFNetworking. I am attempting to write a small Craigslist client for iPhone. So far my networking code is as follows:

NSArray *fetchedData = [_fetchedResultsController fetchedObjects];
for (NHXsearch *search in fetchedData) {
    NSURL *url = [NSURL URLWithString:search.searchURL];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

    operation.responseSerializer = [AFHTTPResponseSerializer serializer];
    operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];

    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"Success! %@", responseObject);

    }failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Failure, %@", error);
    }];

    [_queue addOperation:operation];
}

_isLoading = NO;
[self.tableView reloadData];

So my code takes all of my searches in the fetched results controller, and uses each of their searchURL properties as a url for AFHTTPResponseSerializer.

The links work correctly when I paste them into my browser and give me the equivalent of doing the search with the object's properties then clicking craigslist's RSS button. However, despite the page being XML formatted (?) using AFXMLParserResponseSerializer gives me the following:

{ status code: 404, headers { } }, NSUnderlyingError=0x1095b3440 "Request failed: unacceptable content-type: text/plain"}

When I switch to AFHTTPResponseSerializer and add operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"]; I get:

Failure, Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: not found (404)" UserInfo=0x1095055e0 {AFNetworkingOperationFailingURLResponseErrorKey= { URL: http://richmond.craigslist.org/search/sss?query=xbox&s=0&sort=date&format=rss } { status code: 404, headers { } }, NSLocalizedDescription=Request failed: not found (404), NSErrorFailingURLKey=http://richmond.craigslist.org/search/sss?query=xbox&s=0&sort=date&format=rss}

I'm very confused how to go about this. I've tried using SMXML and SMXMLDocumentResponseSerialization, which gives me success, but also gives me <(null)/> as a responseObject. Any help would be appreciated.

0

There are 0 best solutions below