Encoding issue with ASIHttpRequest response

Guys, I tried hard and did not succeed.

Creature:

    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:self.urlString]]; 
request.delegate = self;
[request setDefaultResponseEncoding:NSUTF8StringEncoding];
[request setResponseEncoding:NSUTF8StringEncoding];
[request setRequestMethod:@"PUT"];
[request addRequestHeader:@"Accept" value:@"application/xml"];
[request addRequestHeader:@"Content-Type" value:@"application/xml; charset=UTF-8;"];

Desplaying:

- (void)requestFinished:(ASIHTTPRequest *)request
{
        [self HideProgressing];

//      NSString *poweredBy = [[request responseHeaders] objectForKey:@"X-Powered-By"];
//      NSString *contentType = [[request responseHeaders] objectForKey:@"Content-Type"];

        NSString *body = [request responseString];
        //NSString *body = [[NSString alloc] initWithData:[request responseData] encoding:NSUTF8StringEncoding];
        NSLog(@"%@\n%@", body, request.responseStatusMessage);

Even the "content type" says it has UTF-8. But I only see characters like "& # 4857" instead of Cyrillic characters.

Did anyone solve the same encoding problem?

Data taken from the Basecamp API if that helps. Thank.

alt text

+3
source share
1 answer

This is an HTML encoding / decoding issue. Please note that URL encoding / decoding is different.

Cyrillic Encoding / Decoding Table - http://webdesign.about.com/od/localization/l/blhtmlcodes-ru.htm

: http://code.google.com/p/statz/source/browse/trunk/NSString%2BHTML.h http://code.google.com/p/statz/source/browse/trunk/NSString%2BHTML.m

: https://github.com/mwaterfall/MWFeedParser/blob/master/Classes/GTMNSString%2BHTML.m

, .

.

0

Source: https://habr.com/ru/post/1773777/


All Articles