ASIHttpRequest 响应的编码问题
伙计们,我已经尝试了一切,但没有成功。
创建:
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(如果有帮助的话)。谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 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
我还没有实现,还有另一个现在的任务。
祝你好运。
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.