1.AFNetwork
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSString *reqStr = [NSString stringWithFormat:@"%@%@.do",@"http://172.20.0.11:8080/quickLogin/quickApp/tom/",_contentStr];
[manager GET:reqStr
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
float sta = [[responseObject objectForKey:@"status"] floatValue];
if (sta == 1) {
[self alShow:@"PC端成功登錄"];
}else if (sta == 0){
[self alShow:@"PC端登錄失敗"];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error:%@",error);
}];
其實(shí)這個(gè)沒什么問題击困,主要就是涎劈,你要讓服務(wù)器端考慮周全,要不然你這里將會遇到一堆蛋疼的Bug阅茶。
{ status code: 200, headers {
"Content-Length" = 12;
"Content-Type" = "text/plain;charset=ISO-8859-1";
Date = "Thu, 17 Apr 2014 09:38:46 GMT";
Server = "Apache-Coyote/1.1";
} }, NSLocalizedDescription=Request failed: unacceptable content-type: text/plain}
這里一看就知道是服務(wù)器端格式問題蛛枚,服務(wù)器端沒有設(shè)置好,只是設(shè)置成了text/plain,假如非要你那里改也是可以的脸哀,加上這個(gè):
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
但是你這樣改了之后蹦浦,成功后返回的responseObject解析要出問題了,所以還是服務(wù)器端統(tǒng)一做一下處理把!
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x17d72560'
還有一些bug基本上撞蜂,你直接copy錯(cuò)誤盲镶,stackoverflow上就能找到答案了,我就不廢話了蝌诡。