ASIHTTPRequest + SBJSon iphone

202 views Asked by At

I am working with an application where I have to request a url and I get the response accordingly

I am using ASIHTTPRequest to request the URL here is my request

-(void)getTips {
    if ([CommonFunctions networkConnected]) {
        ShowNetworkActivityIndicator();
        NSString *strPhp = @"staticpage.php";
    NSString *strQuery = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%@%@?static_id=3",GMS_URL,strPhp]];
        ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:strQuery]];
        NSLog(@"tips url %@",request.url);
        request.delegate = self;
        [request setRequestMethod:@"GET"];
        [request startAsynchronous];
    }
}

These are my delegate methods

-(void)request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data {

//    NSString *responseStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//    NSLog(@"responseStr %@",responseStr);
    SBJsonParser *json = [[SBJsonParser alloc]init];
    NSLog(@"json data %@",[json objectWithData:data]);
    NSMutableArray *marrData = [[json objectWithData:data] valueForKey:@"responseData"];
    if([[marrData valueForKey:@"result"] isEqualToString:@"failed"]){
        [CommonFunctions showAlertMessage:[marrData valueForKey:@"error"]];
    }
    HideNetworkActivityIndicator();
}

Here I get null data no matter whether I pass request methods GET or POST

When I check the same url in browser I get the response and a valid json from online json viewer

What are the possible reason that I am getting null data in the application

1

There are 1 answers

1
oldrinmendez On

Use requestFinished: delegate.. Please try this.

-(void)requestFinished:(ASIHTTPRequest *)request
{
   NSLog(@"response %@", [request responseString]);
}