1。發一個get請求,
AFHTTPClient *bClient = [AFHTTPClient clientWithBaseURL
[NSURLURLWithString:@"http://xxxx.com"]];
[bClientgetPath:nilparameters:nilsuccess:^(AFHTTPRequestOperation *operation,id responseObject)
{
NSLog(@"response description:%@",[responseObjectdescription]);
}
failure:^(AFHTTPRequestOperation *operation,NSError *error)
{
NSLog(@"error description:%@",[error description]);
}];
2。發一個post請求
NSDictionary *dic = [[NSDictionaryalloc]initWithObjectsAndKeys:@"123",@"num",@"jack",@"name",nil];
AFHTTPClient *aClient = [AFHTTPClientclientWithBaseURL:[NSURLURLWithString:@"http://www.xxxx.com"]];
//設置接受的數據類型爲json
[aClientsetDefaultHeader:@"Accept"value:@"application/json"];
//設置提交的數據編碼類型爲json格式
[aClient setParameterEncoding:AFJSONParameterEncoding];
[aClientpostPath:nilparameters:dicsuccess:^(AFHTTPRequestOperation*operation,id responseObject)
{
NSLog(@"response description:%@",[responseObject description]);
}
failure:^(AFHTTPRequestOperation *operation,NSError *error)
{
NSLog(@"error description:%@",[errordescription]);
}];
http://www.cocoachina.com/applenews/devnews/2013/1106/7304.html