我正在将 JSON POST 请求中的 base64 图像发送到 php 服务器。响应来了。但是空格被添加到 base64 字符串中。所以当我尝试解码base64时,它失败了。无法理解问题出在哪里。我正在开发一个 iPad 应用程序并从 iPad 模拟器发送请求。
让我知道您是否对可能出现的问题有丝毫的了解。非常感谢。
以下是我用于发送请求的 ASIRequest 代码 -
ASIFormDataRequest *asiRequest = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:urlForAPI]];
[asiRequest setTimeOutSeconds:200];
NSMutableDictionary *requestheaders =[[[NSMutableDictionary alloc]init] autorelease];
[requestheaders setValue:@"application/x-www-form-urlencoded; charset=utf-8" forKey:@"Content-Type"];
NSData *jsonData = [data JSONData];
NSString *string = [[[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding] autorelease];
[asiRequest setRequestHeaders:requestheaders];
NSString *jsonString = [NSString stringWithFormat:@"REQUEST=%@",string];
NSData *requestData = [NSData dataWithBytes:[jsonString UTF8String] length:[jsonString length]];
[asiRequest setPostBody:[NSMutableData dataWithData:requestData]];
[asiRequest setShouldContinueWhenAppEntersBackground:YES];
[asiRequest setDelegate:self];
[asiRequest setRequestMethod:@"POST"];
[asiRequest setDidFailSelector:@selector(uploadFailed:)];
[asiRequest setDidFinishSelector:@selector(uploadFinished:)];
[asiRequest startSynchronous];