如何检测HTTP响应,解析xml并保存到NSString? [英] How do I detect a HTTP response, parse the xml and save to a NSString?

查看:57
本文介绍了如何检测HTTP响应,解析xml并保存到NSString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了好几个星期了,但仍然一无所获.我正在使用ASIHTTPRequest,并且已成功将数据发送到服务器,现在我需要获取响应XML,对其进行解析并将其保存到每个标记为NSString的元素中,以便将其发布到服务器.有没有人知道如何执行此操作?

I've been trying to figure this out for weeks and i still get nothing. I am using the ASIHTTPRequest and ive successfully sent the data to a server and now I need to get the response XML,parse it and save the elements to each labeled NSString so I can post it to the server. Does anyone have an idea on how to do this?

推荐答案

通过查看如何使用页,我想您要做的是实现在请求完成后可以调用的方法.例如,假设您有要在请求完成时调用的方法done:.您可以在请求中将该方法设置为完成"选择器:

From looking at the How to Use page, I think what you want to do is implement methods that can be called when the request is complete. For example, say you have a method done: that you want to be called when your request completes. You can set that method as your "finished" selector on the request:

NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[request setDelegate:self];
[request setDidFinishSelector:@selector(done:)];

然后,您实现done:方法:

- (void)done:(ASIHTTPRequest *)request
{
   NSString *response = [request responseString];
}

所有这些都假设您正在异步发送请求;如果您使用的是同步调用,则可以仅在请求中使用responseString属性.

This is all assuming you're sending the requests asynchronously; if you're using synchronous calls, you can just use the responseString property on the request.

这篇关于如何检测HTTP响应,解析xml并保存到NSString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆