iOS 网络部分

http上传图片


服务器提供的信息

Content-Disposition: form-data; name="image_file"; filename="pic.jpg"



  AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"image/png",@"image/jpg",nil];
    //NSURL *filePath = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@",fullPath]];
    
    [manager POST:@"http://api.0579.com/up/upload.php" parameters:nil constructingBodyWithBlock:^(id formData) {
        NSString *path=[[NSBundle mainBundle] pathForResource:@"3" ofType:@"png"];
  
        
        
        UIImage *image=[UIImage imageNamed:@"3.png"];
        NSData *data=[NSData dataWithContentsOfURL:imageURL];
        
        data=UIImagePNGRepresentation(image);
        
        
        
        [formData appendPartWithFileData:data name:@"image_file"
                                fileName:@"3.png" mimeType:@"image/png"];
        
        
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"respon%@",responseObject);
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error%@",error);
        
    }];


你可能感兴趣的:(iOS 网络部分)