我是我的 iphone 应用程序,我想将图像发布到链接。该图像是从手机图库中选择的。我将该图像转换为nsstring。但我在发帖时出错。
错误是:(“错误域=org.brautaset.JSON.ErrorDomain Code=3 \"无法识别的前导字符\" UserInfo=0x9e599a0 {NSLocalizedDescription=无法识别的前导字符}")
我正在使用以下代码
用于将图像转换为字符串:
CGFloat compression = 0.25f;
NSData *imagedata = UIImageJPEGRepresentation(self.profileImageView.image, compression);
profileObj.profileImageString = [[NSString alloc]initWithData:imagedata encoding:NSASCIIStringEncoding];
profileObj.profileImageString = [profileObj.profileImageString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"profileObj.profileImageString: %@",profileObj.profileImageString);
发布到链接:
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
ProfileObject *profile_obj=obj;
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@upload/register/john@gmail.com/password/774e4b7b118994b1c58d71c088834d43ca2937623319f6b7b6c48a1846132027/iPhone/1/%@",MainUrl,profile_obj.profileImageString]];
NSLog(@"url is---%@",url);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[request setHTTPMethod:@"POST"];
[request setValue:@"multipart/form-data" forHTTPHeaderField:@"Content-Type"];
NSError* error = nil;
NSURLResponse* response;
NSData* result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *dataString=[[NSString alloc]initWithData:result encoding:NSUTF8StringEncoding];
NSMutableDictionary *getResponseDict = [[NSMutableDictionary alloc] init];
[getResponseDict addEntriesFromDictionary:[dataString JSONValue]];
NSString *responseStr=[getResponseDict objectForKey:@"message"];
NSLog(@"responseStr is....%@",responseStr);
return responseStr;
对不起,我的英语很差 别介意。
提前致谢