Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
  2. initWithURL:[NSURL
  3. URLWithString:@"https://testservice.fiamm.com/token"]];
  4.  
  5. [request setHTTPMethod:@"POST"];
  6. [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-type"];
  7.  
  8. NSString *postString = @"username=TestIphone&Password=T3st1ph$n&Grant_type=password";
  9.  
  10. [request setValue:[NSString stringWithFormat:@"%d", [postString length]] forHTTPHeaderField:@"Content-length"];
  11.  
  12. [request setHTTPBody:[postString
  13. dataUsingEncoding:NSUTF8StringEncoding]];
  14.  
  15. // Fetch the JSON response
  16. NSData *urlData;
  17. NSURLResponse *response;
  18. NSError *error;
  19.  
  20. // Make synchronous request
  21. urlData = [NSURLConnection sendSynchronousRequest:request
  22. returningResponse:&response
  23. error:&error];
  24.  
  25. // Construct a String around the Data from the response
  26. NSString *strFiamm = [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
  27.  
  28. http://testservice.fiamm.com/token
  29. username=TestIphone
  30. Password=T3st1ph$n
  31. Grant_type=password
  32.  
  33. 403 - Forbidden: Access is denied.
  34. You do not have permission to view this directory or page using the credentials that you supplied.
  35.  
  36. -(void) connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *) challenge {
  37.  
  38. if ([challenge.protectionSpace.authenticationMethod isEqualToString: NSURLAuthenticationMethodServerTrust])
  39. {
  40.  
  41. NSURL* baseURL = [NSURL URLWithString:@"yourURL”];
  42.  
  43. if ([challenge.protectionSpace.host isEqualToString:baseURL.host])
  44. {
  45. SecTrustRef trust = challenge.protectionSpace.serverTrust;
  46.  
  47. NSURLCredential *cred = [NSURLCredential credentialForTrust:trust];
  48.  
  49. [challenge.sender useCredential:cred forAuthenticationChallenge:challenge];
  50.  
  51. }
  52. else
  53. NSLog(@"Not trusting connection to host %@", challenge.protectionSpace.host);
  54.  
  55. }
  56. [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement