0

I need to send a POST request to a website to load more results of the page (There is about 200 results that I want to parse (using TFHpple) but the page is showing just 40 and you need to click "Show More Results" at the button to load more (there is 4 pages))).

Every time one or two addresses are different and the other is the same, why is it? All of them should be different.

I tried to search the web how to send a POST request and I tried but it hasn't succeeded :( Can anyone help me figure it out?

General information:

Remote Address:212.117.156.55:80

Request URL:http://www.d.co.il/DOTNET/ajax/GetMoreResults

Request Method:POST

Status Code:200 OK

File Name: GetMoreResults

If there is any additional information required, just write in and I'll give you it.

Thank you very much!

Am I done this right?

NSURL *url=[NSURL URLWithString:@"http://www.d.co.il/SearchResults/?query=%D7%A9%D7%95%D7%A4%D7%A8%D7%A1%D7%9C&type=tag&location="];
NSData *data=[NSData dataWithContentsOfURL:url];

TFHpple *parser=[TFHpple hppleWithHTMLData:data];

NSString *XpathQueryString=@"//p[contains(@class, \"result-contact-address\")]";

NSArray *Nodes=[parser searchWithXPathQuery:XpathQueryString];


for (int i=0; i<4; i++)
{
    NSError *error;

    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
    NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
    NSURL *postUrl = [NSURL URLWithString:@"http://www.d.co.il/DOTNET/ajax/GetMoreResults"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:postUrl
                                                           cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                       timeoutInterval:60.0];

    [request addValue:@"GetMoreResults" forHTTPHeaderField:@"Content-Type"];
    [request addValue:@"GetMoreResults" forHTTPHeaderField:@"Accept"];

    [request setHTTPMethod:@"POST"];
    NSDictionary *mapData = [[NSDictionary alloc] initWithObjectsAndKeys: @"80", @"batchNumber",
                             @"IOS TYPE", @"typemap",
                             nil];
    NSData *postData = [NSJSONSerialization dataWithJSONObject:mapData options:0 error:&error];
    [request setHTTPBody:postData];


    NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

    }];

    [postDataTask resume];
}
int i=1;
for (TFHppleElement *element in Nodes) {
    NSString *address = element.text;
    NSLog(@"%@,%d",address,i);
    i++;
}
Larme
  • 24,190
  • 6
  • 51
  • 81
Yhper
  • 183
  • 2
  • 14
  • 1
    Not sure why you are opening a new thread when you are already on [this thread](http://stackoverflow.com/questions/33343276/send-a-post-request-objective-c/33343957?noredirect=1#comment54488350_33343957). – Abhinav Oct 26 '15 at 15:44
  • @Abhinav I've wrote to you in the other thread, can you please help me? – Yhper Oct 26 '15 at 16:11
  • Please don't mind but I already gave you direction and enlightened your path. But you are looking for too much spoon feeding. May be other SO can pitch in close your issue. I would rather advise you to not open multiple threads with same issue. – Abhinav Oct 26 '15 at 16:15

0 Answers0