Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Sergio10

macrumors regular
Original poster
Hi,

How to implement REST XML?

What does it mean in general? As I understand application sends request as http. And receives XML as respons.
Correct?

Thank you
 
to call some GET REST Service
Code:
- (void)getPickUpLinesFromWebService{
	[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:TRUE];
	NSString *URLstr = GET_PICKUP_LINES_URL;
	
	NSURL *theURL = [NSURL URLWithString:URLstr];
	NSURLRequest *theRequest = [NSURLRequest requestWithURL:theURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
	
	NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
	
	if(theConnection){
		responseData = [[NSMutableData data] retain];
	}
	else{
		[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:FALSE];
	}

}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
	[responseData appendData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
	[self parsePickUpLines:responseData];
	[connection release];
	[responseData release];
}

- (void)parsePickUpLines:(NSData *)pickUpLinesXMLData{
	if(pickUpLinesParser)
		[pickUpLinesParser release];
	pickUpLinesParser = [[NSXMLParser alloc] initWithData:pickUpLinesXMLData];
	[pickUpLinesParser setDelegate:self];
	[pickUpLinesParser setShouldResolveExternalEntities:NO];
	[pickUpLinesParser parse];
}

And the you implement NSXMLParser delegate Methods

For POST REST Service
Code:
- (void)SomeServiceMethod
{
	NSData *thumbsupData = [[NSString stringWithFormat:
								 @"<rootElement> \
								<element> \
								<line_id>%@</line_id> \
								<thumbsup>%@</thumbsup> \
								</element> \
								 </rootElement>",  line_id]
								dataUsingEncoding: NSASCIIStringEncoding];
	

	
	NSString *URLstr = SOME_URL;
	NSURL *theURL = [NSURL URLWithString:URLstr];
	
	NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL];
	
	[theRequest setHTTPMethod:@"POST"];
	[theRequest setValue:@"text/xml"forHTTPHeaderField:@"Content-type"];
	[theRequest setHTTPBody:thumbsupData];
	
	[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:TRUE];
	
	NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
	if(!theConnection){
		NSLog(@"Error, Invalid Request");
		
	}
}

Its pretty easy just follow the code youll understand
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.