-5

Problem in ios.

I have a problem regarding the webservice data fetching.i have two websevice named getManagerEvents and WhoAreComing.i want to get a eventid from the getManagerEvents and then after in another class i have to print the data based on the eventid and call the another whoarecoming webservice and print the data in the based on the both webservices.

Code:

NSString *strURL = [NSString stringWithFormat:@"%@getManagerEvents?ManagerId=%d",WEBSERVICE_URL,kSHARED_INSTA‌NCE.axcessUser.iUserId];

ASIHTTPRequest *eventListRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:strURL]]; 
[eventListRequest setRequestMethod:@"GET"]; 
[eventListRequest startSynchronous]; 

SBJsonParser *json =[[SBJsonParser alloc]init]; 

NSDictionary *dictResponse = [json objectWithString:eventListRequest.responseString]; 
[HUD hide:YES]; 
[self parseResponse:dictResponse]; 
Popeye
  • 11,839
  • 9
  • 58
  • 91
Ankit
  • 286
  • 4
  • 16

1 Answers1

1

Use below code for this:

- (void)getData
{
    NSString *urlAsString = [NSString stringWithFormat:@"http://yourURL.php"];
    NSURL *url = [NSURL URLWithString:urlAsString];

    NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
    [urlRequest setTimeoutInterval:30.0f];
    [urlRequest setHTTPMethod:@"POST"];

    NSString *queryStr = [NSString stringWithFormat:@"yourParameter=%d",parameterValue];
    NSData *bodyData = [queryStr dataUsingEncoding:NSUTF8StringEncoding];

    [urlRequest setValue:@"application/x-www-form-urlencoded"
      forHTTPHeaderField:@"Content-Type"];
    [urlRequest setHTTPBody:bodyData];

    NSURLResponse *response = nil;
    NSError *error = nil;

    NSData *responseData = [NSURLConnection sendSynchronousRequest:urlRequest
                                                 returningResponse:&response
                                                             error:&error];


    if ([responseData length] > 0  &&
        error == nil) {

        NSDictionary *resultDict = [NSJSONSerialization
                                    JSONObjectWithData:responseData
                                    options:kNilOptions
                                    error:&error];

        NSLog(@"%@",resultDict);

    }

}
Ashutosh
  • 2,215
  • 14
  • 27
  • Why synchronous? While the rest of the approach seems reasonable, a _synchronous_ invocation of a network request is always suboptimal, and can be avoided easily. – CouchDeveloper Jan 17 '14 at 07:33
  • Get a specific Data from NSDictionary into the string and based on that string i have to print data in another class. How to do it ? – Ankit Jan 17 '14 at 07:39
  • Call that class with the parameter of fetched data – Kumar KL Jan 17 '14 at 07:42