Encoding problem with ASIHttpRequest response
-
29-09-2019 - |
Question
Guys, I've tryied all and had not success.
Creating:
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 "content-type" says it has UTF-8. But I see only stuff like "ዹ" instead cyrillic symbols.
Did somebody solve the same problem with encodings?
Data is from Basecamp API, if it helps. Thanks.
Solution
That's a HTML Encode/decode problem. Note, URL encode/decode is different one.
Encode/decode table for cyrillic - http://webdesign.about.com/od/localization/l/blhtmlcodes-ru.htm
The code approach: http://code.google.com/p/statz/source/browse/trunk/NSString%2BHTML.h http://code.google.com/p/statz/source/browse/trunk/NSString%2BHTML.m
Or this one: https://github.com/mwaterfall/MWFeedParser/blob/master/Classes/GTMNSString%2BHTML.m
I've not implemented yet, have another tasks now.
Good luck.