问题描述
- 用AFNetworking 上传图片问题!
- UIImageView *imageView1 = (UIImageView *)[self.view viewWithTag:200];
NSData *data = UIImagePNGRepresentation(imageView1.image); NSString *S = [data base64Encoding];
// NSString *path = KUploadDectFile;
NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:@""AB000990""@""RecordId""@""1""@""SeqNO""@""""@""URL""@""2014-8-18""@""UploadDate"" nil]; NSString *str = [dic JSONString]; NSLog(@""str = %@""str); NSDictionary *dic1 = [[NSDictionary alloc] initWithObjectsAndKeys:str@""json""S@""fileString""nil]; AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@""http://192.168.1.200:8002""]];
// AFHTTPClient *httpClient = [CNGlobal shareGlobal].httpClient;
/* NSMutableURLRequest *request = [httpClient requestWithMethod:@""POST"" path:@""/PhoneService.asmx/UploadDectFile"" parameters:dic1]; [request setHTTPBody:data]; AFHTTPRequestOperation *operation = [httpClient HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation id responseObject) { NSLog(@""成功!""); } failure:^(AFHTTPRequestOperation *operation NSError *error) { NSLog(@""失败! error = %@""error); }]; [httpClient enqueueHTTPRequestOperation:operation]; */ NSURLRequest *request = [httpClient multipartFormRequestWithMethod:@""POST"" path:@""/PhoneService.asmx/UploadDectFile"" parameters:dic1 constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { [formData appendPartWithFileData:data name:@""IMAGE"" fileName:@""face.png"" mimeType:@""image/png""]; }];
// [AFHTTPRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@""text/html""]];
AFHTTPRequestOperation *operation = [httpClient HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation id responseObject) { NSLog(@""成功!""); } failure:^(AFHTTPRequestOperation *operation NSError *error) { NSLog(@""失败! error = %@""error); }]; [httpClient enqueueHTTPRequestOperation:operation];
这是我上传图片的代码~ 老是错误提示code = -1011
时间: 2024-11-15 23:23:20