今天在嘗試用AFNetworking,但是請(qǐng)求貌似沒(méi)有發(fā)出的樣子@interface TestAFNetworkingClient : AFHTTPClient+ (TestAFNetworkingClient *)sharedClient;@end@implementation TestAFNetworkingClient+ (TestAFNetworkingClient *)sharedClient
{ static TestAFNetworkingClient *_sharedClient = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{
_sharedClient = [[TestAFNetworkingClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://example.com/"]];
});
return _sharedClient;
}
- (id)initWithBaseURL:(NSURL *)url { self = [super initWithBaseURL:url]; if (!self) { return nil;
} return self;
}@end@implementation TestAppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
}
TestAFNetworkingClient *afClient = [TestAFNetworkingClient sharedClient];
[afClient getPath:@"testfile.txt"
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Success.");
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"error.");
}];我換了更簡(jiǎn)單的代碼 AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://baidu.com"]];
[client getPath:@"" parameters:nil success:^(AFHTTPRequestOperation *op, id obj) {NSLog(@"success.");} failure:nil];也是一樣沒(méi)效果偶爾還會(huì)報(bào)錯(cuò) ADDRESPONSE - ADDING TO MEMORY ONLY: http://baidu.com/
這個(gè)代碼運(yùn)行起來(lái),貌似block里的兩段代碼都沒(méi)有運(yùn)行的樣子
慕尼黑的夜晚無(wú)繁華
2023-05-01 15:11:31