url上传的地址
dic上传的参数
data上传图片的二进制数据
QianXiBlockHandle 上传成功的block回调
QianXiBlockError上传失败的block回调
+(void)replacePlantMessage:(NSString*)url andPOSTdic:(NSMutableDictionary*)dict andImageData:(NSData*)data blochHandle:(QianXiBlockHandle)dic ifError:(QianXiBlockError)str{
AFSecurityPolicy*securityPolicy = [[AFSecurityPolicy alloc]init];
[securityPolicy setAllowInvalidCertificates:YES];
NSString*strw =@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<root>"
"<command_type>***</command_type>"
"<id>***</id>"
"<action>***</action>"
"<value>***<avlue>"
"</root>";
//NSDictionary * di = @{@"id":@"1289",@"num":@"1",@"op":@"6",@"user_img":@"ni",@"test" : strw};
[dict setObject:strw forKey:@"test"];
AFHTTPSessionManager* manager = [AFHTTPSessionManager manager];
manager.responseSerializer= [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes= [NSSet setWithObjects:@"text/html",nil];
[manager POST:url parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
if(data) {
[formData appendPartWithFileData:data name:@"photo" fileName:@"123.png"mimeType:@"image/jpg"];
}
}progress:progress:^(NSProgress*_NonnulluploadProgress){
//上传的进度
}success:^(NSURLSessionDataTask*_Nonnull task,id _Nullable responseObject) {
//上传进度
}
NSLog(@"%@",responseObject);
NSDictionary* dics = [NSJSONSerialization JSONObjectWithData:responseObjectoptions:NSJSONReadingAllowFragments error:nil];
NSLog(@"nbcom====%@",dics);
if(dic) {
dic(dics);
}
}failure:^(NSURLSessionDataTask * _Nullable task,NSError*_Nonnull error) {
NSLog(@"请求失败:%@",error);
}];}
网友评论