0

Could you help me, with a example, where i consume a json webservice in a https url. i have tried: where urlConParametros is a https url.

NSString* encriptado = nil;
NSString* urlConParametros = [NSString stringWithFormat:@"%@%@?%@=%@", URL, metodo, key, valorSinEcncriptar];
NSError* error;
if(encriptado == nil){
    NSMutableURLRequest *getRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlConParametros]];
    [getRequest setHTTPMethod:@"GET"];
    NSError *requestError;
    NSURLResponse *urlResponse = nil;
    NSData *response1 =[NSURLConnection sendSynchronousRequest:getRequest returningResponse:&urlResponse error:&requestError];
    NSString* data = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlConParametros] encoding:NSUTF8StringEncoding
                                           error:&error];
    return data;
}

but return data nil. My problem is that with http, the same web service response the correct data, but when it doing with https, the response is nil.

  • How can this Question be related to Xcode ? – Bhavin Jul 16 '13 at 14:20
  • My first guess would be parameter encoding. Is there a simpler endpoint in the web service that doesn't take parameters? Start with that and see if you can make a simple get work. Then look at this http://stackoverflow.com/questions/8088473/url-encode-an-nsstring. Also, consider changing to asynchronous once you get this working. – danh Jul 16 '13 at 15:34
  • Sorry, it's not Xcode, its IOS question. – user2587694 Jul 17 '13 at 06:48

1 Answers1

0

Please add some more details in the Question about What you want exactly, What you have tried and What are the Problems you are facing while implementation ?

If you want to GET some data from the Web Service , you can get it like this. :

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlConParametros]];
NSString *respStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"My Response :: %@",respStr);

If the Response is in JSON Format then you should do something like this :

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlConParametros]];
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@"My Response :: %@",json);

Take a look at the Sample Code for AdvancedURLConnections.

Bhavin
  • 27,155
  • 11
  • 55
  • 94