Send an HTTP GET request in iOS
Suppose you want to send the http get request to the server with some parameters.If the request is successfully sent to the server, you will get some data. And use that data according to your need. Here is the example of how to Send an HTTP GET request in iOS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
NSMutableString *params = [NSMutableString string]; NSString *screenWidth = [NSString stringWithFormat:@"%f", SCREEN_WIDTH]; [params appendFormat:@"ws_key=%@&", WS_KEY]; [params appendFormat:@"id_lang=%@&", [preferences objectForKey:@"id_lang"]]; [params appendFormat:@"id_currency=%@&", [preferences objectForKey:@"id_currency"]]; [params appendFormat:@"width=%@&", screenWidth]; NSString *urlString = [NSString stringWithFormat:@"%@%@?%@",BaseDomain,@"...",params]; NSMutableURLRequest *request1 = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@",urlString,params]] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10 ]; [request1 setHTTPMethod: @"GET"]; NSError *requestError = nil; NSURLResponse *urlResponse = nil; NSData *response = [NSURLConnection sendSynchronousRequest:request1 returningResponse:&urlResponse error:&requestError]; |