POST 请求
NSString *str=[NSString stringWithFormat:@"http://1.gifclub.applinzi.com/index.php/Home/index/phoneregister"];
//转码
str = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSURL *URL = [NSURL URLWithString:str];
AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];
sessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
sessionManager.responseSerializer=[AFJSONResponseSerializer serializer];
//参数
NSDictionary *parameters = @{@"phoneno":[NSNumber numberWithInteger:15819953627],@"pwd":@"832102",@"nickname":@"林茂佳"};
[sessionManager POST:URL.absoluteString parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"成功---%@",responseObject[@"msg"]);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"错误%@",error);
}];
POST上传用户头像
NSString *str=[NSString stringWithFormat:@"http://1.gifclub.applinzi.com/index.php/Home/index/uploadheadpicture"]; str = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; NSURL *URL = [NSURL URLWithString:str]; AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager]; sessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"]; sessionManager.responseSerializer=[AFJSONResponseSerializer serializer]; UIImage *image = [UIImage imageNamed:@"b.png"]; NSData *imageData = UIImagePNGRepresentation(image);//PNG 转Data
//参数
NSDictionary *parameter = @{@"userid":@"113b960b52fa1fb8505108982141a08b"}; [sessionManager POST:URL.absoluteString parameters:parameter constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) { NSString *fileName =@"b.png"; [formData appendPartWithFileData:imageData name:@"photo" fileName:fileName mimeType:@"image/png"]; } progress:^(NSProgress * _Nonnull uploadProgress) { } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { NSLog(@"成功---%@",responseObject); NSLog(@"成功---%@",responseObject[@"msg"]); } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSLog(@"错误%@",error);
}];
GET 请求
NSString *str=[NSString stringWithFormat:@"http://app.95e.com/vm/getMaterial2.aspx?name=粉丝"];
str = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSURL *URL = [NSURL URLWithString:str];
AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];
sessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[sessionManager GET:URL.absoluteString parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
NSLog(@"总进度---%lld", downloadProgress.totalUnitCount);
NSLog(@"进度---%lld", downloadProgress.completedUnitCount);
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"json----%@", responseObject);
[HUD removeFromSuperview];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"error---%@",error);
}];
发布gif
NSString *str=publishgif;
str = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSURL *URL = [NSURL URLWithString:str];
AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager]; sessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"]; sessionManager.responseSerializer=[AFJSONResponseSerializer serializer];
// 参数
NSDictionary *parameter = @{@"ownerid":@"113b960b52fa1fb8505108982141a08b",@"text":@"ios27"};
NSString *theupfilePath=[[NSBundle mainBundle]pathForResource:@"dd" ofType:@"gif"]; //拿到图片
NSData *imageData=[NSData dataWithContentsOfFile:theupfilePath]; [sessionManager POST:URL.absoluteString parameters:parameter constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
NSString *fileName =@"hehe.gif";
[formData appendPartWithFileData:imageData name:@"gifname" fileName:fileName mimeType:@"gif"];
} progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"成功---%@",responseObject);
} failure:^(NSURLSessionDat
aTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"错误%@",error);
}];