伙计们,我已经尝试了所有但没有成功。
创建:
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;"];
显示:
- (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);
甚至“内容类型”也说它有 UTF-8。但我只看到像“ዹ”这样的东西而不是西里尔符号。
有人用编码解决了同样的问题吗?
如果有帮助,数据来自 Basecamp API。谢谢。
最佳答案
这是一个 HTML 编码/解码问题。请注意,URL 编码/解码是不同的。
西里尔字母的编码/解码表 - 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
我还没有实现,现在有其他任务。
祝你好运。
关于iphone - ASIHttpRequest 响应的编码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4131210/