最近我一直在做一个 iOS 项目。我想将我的图片发送到服务器。我使用 xmlrpc 来执行此操作,但是当我编写这样的代码时:
- (void)uploadImage:(UIImage *)sourceImage ForName:(NSString *)imageName
{
NSData *imageData = UIImagePNGRepresentation(sourceImage);
NSString *imageString = [imageData base64EncodedString];
NSURL *URL = [NSURL URLWithString: SERVER_URL];
XMLRPCRequest *request = [[XMLRPCRequest alloc]
initWithURL:URL];
NSArray *params = [NSArray arrayWithObjects:imageName,imageString,nil];
[request setMethod:@"upload_image" withParameter:params];
我给参数“imageName”,它会失败。但是如果我写这样的代码
- (void)uploadImage:(UIImage *)sourceImage
{
NSData *imageData = UIImagePNGRepresentation(sourceImage);
NSString *imageString = [imageData base64EncodedString];
NSURL *URL = [NSURL URLWithString: SERVER_URL];
XMLRPCRequest *request = [[XMLRPCRequest alloc]
initWithURL:URL];
NSString *imageName = @"hello.png";
NSArray *params = [NSArray arrayWithObjects:imageName,imageString,nil];
[request setMethod:@"upload_image" withParameter:params];
没关系,我可以将图片上传到服务器。我不知道为什么,有人可以解释一下吗?