1

这是我用来执行 HTTP GET 请求的方法。如何将其更改为使用 HTTPS?

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);
    }
}
4

1 回答 1

3

是的。

HTTP/HTTPS 由 URL 的方案确定,在您的情况下,该方案在AS_NET_BASE_URL.

于 2013-08-20T21:30:03.467 回答