R – How to detect a HTTP response, parse the xml and save to a NSString

asihttprequestiphonensstringobjective cxml

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?

Best Answer

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:)];

Then later, you implement the done: method:

- (void)done:(ASIHTTPRequest *)request
{
   NSString *response = [request 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.