Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
- initWithURL:[NSURL
- URLWithString:@"https://testservice.fiamm.com/token"]];
- [request setHTTPMethod:@"POST"];
- [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-type"];
- NSString *postString = @"username=TestIphone&Password=T3st1ph$n&Grant_type=password";
- [request setValue:[NSString stringWithFormat:@"%d", [postString length]] forHTTPHeaderField:@"Content-length"];
- [request setHTTPBody:[postString
- dataUsingEncoding:NSUTF8StringEncoding]];
- // Fetch the JSON response
- NSData *urlData;
- NSURLResponse *response;
- NSError *error;
- // Make synchronous request
- urlData = [NSURLConnection sendSynchronousRequest:request
- returningResponse:&response
- error:&error];
- // Construct a String around the Data from the response
- NSString *strFiamm = [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
- http://testservice.fiamm.com/token
- username=TestIphone
- Password=T3st1ph$n
- Grant_type=password
- 403 - Forbidden: Access is denied.
- You do not have permission to view this directory or page using the credentials that you supplied.
- -(void) connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *) challenge {
- if ([challenge.protectionSpace.authenticationMethod isEqualToString: NSURLAuthenticationMethodServerTrust])
- {
- NSURL* baseURL = [NSURL URLWithString:@"yourURL”];
- if ([challenge.protectionSpace.host isEqualToString:baseURL.host])
- {
- SecTrustRef trust = challenge.protectionSpace.serverTrust;
- NSURLCredential *cred = [NSURLCredential credentialForTrust:trust];
- [challenge.sender useCredential:cred forAuthenticationChallenge:challenge];
- }
- else
- NSLog(@"Not trusting connection to host %@", challenge.protectionSpace.host);
- }
- [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement