/ / Dal server arriva HTML invece di XML: ios, goal-c, xml, rest, nsurlsession

Dal server arriva HTML invece di XML: ios, ogg-c, xml, resto, nsurlsession

Sto inviando una richiesta GET al server, ma i dati arrivano in formato HTML invece che XML. Come posso risolvere questo problema?

NSURL* url = [NSURL URLWithString:@"http://ufa.farfor.ru/getyml/?key=ukAXxeJYZN"];
NSURLSession* session = [NSURLSession sharedSession];
[[session dataTaskWithURL:url
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSLog(@"DATA %@",[NSString stringWithUTF8String:[data bytes]]);
NSLog(@"RESPONSE %@",response);


}] resume];

risposte:

0 per risposta № 1

la codifica potrebbe essere stata un problema?

L'utilizzo di NSWindowsCP1251StringEncoding fornisce dati corretti.

Il seguente codice restituisce i dati xml per me:

    NSURL* url = [NSURL URLWithString:@"http://ufa.farfor.ru/getyml/?key=ukAXxeJYZN"];
NSURLSession* session = [NSURLSession sharedSession];
[[session dataTaskWithURL:url
completionHandler:^(NSData *data, NSURLResponse *response,
NSError *error) {
NSLog(@"Got response %@ with error %@.n", response, error);
NSLog(@"DATA:n%@nEND DATAn",
[[NSString alloc] initWithData: data
encoding: NSWindowsCP1251StringEncoding]);
}] resume];