I have a rest service,(the service URL is a dummy one & doesn’t work)
http://www.testDomain.com/authenticate/
which is username and password authenticated
how do i call this rest service from my application?
The following is the code which i had written in order to consume this REST service(Earlier this service wasn’t user name & password authenticated).
NSString *testUrl=@”http://www.testDomain.com/authenticate/“;
//NSString *testUrl=@"http://www.testDomain.com/authenticate/";
NSMutableURLRequest *request=[[[NSMutableURLRequest alloc]init]autorelease];
[request setHTTPMethod:@"POST"];
[request setURL:[NSURL URLWithString:testUrl]];
[request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
//[request addValue:<#(NSString *)value#> forHTTPHeaderField:<#(NSString *)field#>]
[request setHTTPBody:bodyData];
You have two ways:
unsecured:
ask user for username and pass and send url as http://username:pass@….
support NSUrlConnection delegate:
for u service is better using first way, bcd u anyway not protect link by ssl and somebody smart can sniff all u users and passwords 🙂
p.s. interesting strings is protect from read login/pass from code…