2013-08-20 50 views
1

這是我用來做HTTP GET請求的方法。我如何將其更改爲使用HTTPS?如何做HTTPS GET請求AFNetworking

AS_NET_BASE_URL = http://www.myapp.com

是不是一樣簡單替換HTTP://以https://?

預先感謝您

+(void)startGETRequestAtUrlRoute:(NSString *)route withParameters:(NSString *)slashSeparatedParams completion:(void (^)(BOOL, id))completion{ 

    //If internet is rachable, start request 
    if ([self isInternetReachable]) { 

     //Where request is going 
     AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:AS_NET_BASE_URL]]; 

     NSString *path = [NSString stringWithFormat:@"%@%@%@", AS_NET_BASE_URL, route, slashSeparatedParams]; 

     //Tell operation to expect JSON 
     [httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]]; 
     [httpClient setDefaultHeader:@"Accept" value:@"application/json"]; 

     //Start spinner 
     [self startNetworkIndicator]; 

     //Set up actual GET request 
     [httpClient getPath:path 
       parameters:nil 
        success:^(AFHTTPRequestOperation *operation, id responseObject) { 

         //Stop spinning 
         [self stopNetworkIndicator]; 

         //Make the response JSON valid 
         if (responseObject) { 
          completion(YES, responseObject); 
         } 
        } 

        failure:^(AFHTTPRequestOperation *operation, NSError *error) { 

         [self stopNetworkIndicator]; 

         completion(NO, NULL); 
         //Error 
         NSLog(@"%@", error); 

        } 
     ]; 

     //No internet connection 
    }else{ 
     completion(NO, NULL); 
    } 
} 

回答

3

是。

HTTP/HTTPS由URL的方案確定,在您的情況下,該方案在AS_NET_BASE_URL中指定。