IOS 使用Http模拟SOAP请求Webservice时内容Unicode编码的实现

IOS上去请求WebService时,为了方便,直接用http POST请求。通过对JAVA版本的抓包发现,请求中的中文字符,都被转成Unicode编码。

如:a被换为 a

【其实很简单,获取每个字符的对应的数字,如999,unicode编码即为:ϧ 】

为了实现相关功能,手动将字符串拼接,代码如下:

 

-(NSString *)convert2Unicode:(NSString *)str
{
    NSMutableString *resultString = [[NSMutableString alloc]init];

    NSInteger length =[str length];
    for (int i=0; i<length; i++) {
       // NSLog(@"ConvertString2Unicode ******  charAtIndex%d is %c code:&#%d;",i,[str characterAtIndex:i],[str characterAtIndex:i]);
        [resultString appendString:[NSString stringWithFormat:@"&#%d;",[str characterAtIndex:i]]] ;
    }
    return resultString;
}

 

本人未测试直接传字符串的效果,欢迎指点。

 

posted @ 2015-02-01 13:25  qqsscc  阅读(527)  评论(0编辑  收藏  举报