ASIHttpRequest 响应的编码问题

发布于 2024-10-01 11:07:37 字数 1241 浏览 5 评论 0原文

伙计们,我已经尝试了一切,但没有成功。

创建:

    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。但我只看到像“&#4857”这样的东西,而不是西里尔字母符号。

有人用编码解决了同样的问题吗?

数据来自 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.

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怀念你的温柔 2024-10-08 11:07:37

这是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文