以前,我能够使用以下编码获取 URL 的内容:
<?xml version = "1.0" encoding = "UTF-8"?>
并将其解析为 NSString ,代码如下所示:
NSMutableData *receivedData = [[[NSMutableData alloc] initWithContentsOfURL:[NSURL URLWithString:authenticateURL]] autorelease];
NSString *string = [[[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding] autorelease];if (string) { // if connection established, string will look for <error> in XML
NSRange range = [string rangeOfString:@"<error>"];
if (range.location == NSNotFound) {
result = TRUE;
NSLog(@"Authenticated!"); // if <error> not found, record is present
} //return TRUE to load data
else {
result = FALSE; // <error> found in XML, record is not found
NSLog(@"Not Authenticated!");
}
}
但是,我现在需要获取的内容实际上是没有编码类型的,例如:
<?xml version="1.0" ?><authenticate><auth>Y</auth></authenticate>
因此,现在,当我 NSLog 字符串时,它是空的。已经尝试搜索其他方法,但我发现的所有示例,人们都可以使用 UTF8StringEncoding。很高兴有任何建议:)!谢谢!