Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 似乎在POST请求之前更改了uiimage编码_Ios_Objective C_Uiimage - Fatal编程技术网

Ios 似乎在POST请求之前更改了uiimage编码

Ios 似乎在POST请求之前更改了uiimage编码,ios,objective-c,uiimage,Ios,Objective C,Uiimage,我目前正在将UIImage发送到我的服务器以存储在服务器上。因此,我从用户库中获取图像,然后使用Base64对其进行编码,然后将其发送到我的服务器。但是,我发送到服务器的所有图像都不显示。我想知道我使用base64encodedstring发出的post请求是否会改变编码字符串 这就是我所做的 //Upload picture to server NSData *imageData=UIImageJPEGRepresentation(showPic.image, 1.0f); NSLog(@"T

我目前正在将UIImage发送到我的服务器以存储在服务器上。因此,我从用户库中获取图像,然后使用Base64对其进行编码,然后将其发送到我的服务器。但是,我发送到服务器的所有图像都不显示。我想知道我使用base64encodedstring发出的post请求是否会改变编码字符串

这就是我所做的

//Upload picture to server
NSData *imageData=UIImageJPEGRepresentation(showPic.image, 1.0f);
NSLog(@"The size of the image is %i",[imageData length]);
[Base64 initialize];
NSString *strEncoded = [Base64 encode:imageData];

//NSLog(@"This is the encoded string to be uploaded %@",encodedPic);
prefs=[NSUserDefaults standardUserDefaults];
userid=[prefs stringForKey:@"userid"];

NSLog(@" %@ is the userid to be used to upload the pic",userid);

NSString *poster = @"username=";
poster = [poster stringByAppendingString:userid];
poster = [poster stringByAppendingString:@"&image="];
poster = [poster stringByAppendingString:strEncoded];



NSString *post = poster;
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://www.example.com/server/upload"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
[[NSURLConnection alloc] initWithRequest:request delegate:self];

你能在服务器端收到字符串吗?那么我想你的base64解码在服务器端有问题。你能用一些服务器代码更新你的问题吗?事实上我发现了错误。似乎是使用dataUsingEncoding:NSASCIIStringEncoding从base64字符串中删除所有+符号,从而更改发送到服务器的整个内容。