How to Make REST api call in Objective-C.
We can call using this.NSString *twitterUrl = @"YourUrlString"; NSString *resp = [self makeRestAPICall: twitterUrl];
and method is-(NSString*) makeRestAPICall : (NSString*) reqURLStr { NSURLRequest *Request = [NSURLRequest requestWithURL:[NSURL URLWithString: reqURLStr]]; NSURLResponse *resp = nil; NSError *error = nil; NSData *response = [NSURLConnection sendSynchronousRequest: Request returningResponse: &resp error: &error]; NSString *responseString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; NSLog(@"%@",responseString); return responseString; }
1 2 3 4 |
@interface ViewController : UIViewController<NSURLConnectionDelegate> { NSMutableData *_responseData; } |
Nice post with great details. I really appreciate your idea. Thanks for sharing.
ReplyDelete--------------------------------------------------------------------------------------------------------------
iPhone App Development & iOS App Development & Android Application Development
No longer working in ios8
ReplyDeleteIts deprecated
ReplyDeleteThank you so much for throwing light on such an important aspect of REST API.
ReplyDeleteSQL Server Load Rest Api