如何编码xml数据

时间:2010-04-08 14:09:47

标签: url-encoding nsmutableurlrequest

在我的应用程序中,我必须发送xml数据作为请求,我正在创建像这样的xml字符串

    NSString* str = @"<Item><Name>";
str = [str stringByAppendingFormat:string1];
str = [str stringByAppendingFormat:@"</Name><Description>"];
str = [str stringByAppendingFormat:string2];
str = [str stringByAppendingFormat:@"</Description><Rate>"];
str = [str stringByAppendingFormat:string3];
str = [str stringByAppendingFormat:@"</Rate></Item>"];

之后我创建了一个URLString。

   NSString* curl = @"url?";
curl = [curl stringByAppendingString:@"string"];
curl = [curl stringByAppendingString:@"&apikey=@"value"&searchtext="];
curl = [curl stringByAppendingString:[aString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

我通过传递字符串来创建NSURL  NSURL * finalURL = [NSURL URLWithString:curl];

NSMutableURLRequest * theRequest = [NSMutableURLRequest requestWithURL:finalURL                                                               cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10]; [theRequest setHTTPMethod:@“POST”];

但我没有得到结果

xml字符串的编码是否正确?

任何人都可以帮助我

1 个答案:

答案 0 :(得分:0)