- 我有 NSString ,它是 unicode 编码的。例如 عنم١٢ 在内部表示为
"\U0639\U0646\U0645\U0661\U0662\U0663"
. - 我将此字符串发送到基本上是 LAMP 服务器的远程服务器。请注意,我无权访问该服务器。
- 服务器似乎对 \U 有问题,但对 \u 工作正常。
我尝试了以下对我不起作用的代码:
NSString *resourceparams = [NSString stringWithFormat:@"%@",sender,nil]; NSLog(@"before replace resourceparams: %@", resourceparams); resourceparams = [resourceparams stringByReplacingOccurrencesOfString:@"\\U" withString:@"\\u"]; NSLog(@"after replace resourceparams: %@", resourceparams);
有什么建议么 ?
编辑:(在 Post 请求的正文中添加此数据的发送方式)
NSMutableData *postBody = [NSMutableData data];
[postBody appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
NSEnumerator * enumerator = [[paramDict allKeys] objectEnumerator];
NSString * dataKey = nil;
while (( dataKey = [enumerator nextObject]) ) {
id dataVal = [paramDict objectForKey: dataKey];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundry] dataUsingEncoding:NSUTF8StringEncoding]];
if([dataVal isKindOfClass: [NSData class]]) {
NSString* contentDisposition = [NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"file.ext\"\r\n", dataKey];
[postBody appendData: [contentDisposition dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:dataVal];
} else {
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", dataKey] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[dataVal dataUsingEncoding:NSUTF8StringEncoding]];
}