Prasanth T R
Prasanth T R

Reputation: 11

iPhone RESTful Webservices

I need to create web service in this format in objective c

An example that returns all contacts for a given user might be (where ZmF0aWdhYmxlIGdlbmVyYXR= is a Base64-encoded form of username:password, with the required colon separator):

GET /API/Contacts/username HTTP/1.1
HOST: $baseuri:port
Accept: text/xml
Authorization: Basic ZmF0aWdhYmxlIGdlbmVyYXR=

How to create web service for this format.Please help.

Upvotes: 0

Views: 337

Answers (1)

August Lilleaas
August Lilleaas

Reputation: 54593

Use NSURLRequest.

NSURL *url = [NSURL urlWithString:@"http://foo.com/API/Contacts/username"];
NSMutableURLRequest *req = [[NSMutableURLRequest] initWithUrl:url];
[req setHTTPMethod:@"GET"];
[req setValue:@"text/xml" forHTTPHeaderField:@"Accept"];
[req setValue:@"Basic ZmF0aWdhYmxlIGdlbmVyYXR=" forHTTPHeaderField:@"Authorization"];
[[[NSURLConnection alloc] initWithRequest:req delegate:self] autorelease];
[req release];

Then, implement the delegate methods documented here to handle the responses.

Upvotes: 1

Related Questions