Guest User

Untitled

a guest
Feb 9th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. -(void)getResponseArray:(NSString *)urlstring SoapMessage:(NSString *)soapMessage SoapAction:(NSString *)soapAction1
  2. {
  3. self.urlString = urlstring;
  4. NSString *fullsoapMessage = [NSString stringWithFormat:@"<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body>%@</soap:Body></soap:Envelope>", soapMessage];
  5.  
  6. if(IS_DEBUG)
  7. NSLog(@"The request: %@", fullsoapMessage);
  8.  
  9. NSURL *webserviceurl = [NSURL URLWithString:urlstring];
  10. if (request == nil) {
  11. request = [[NSMutableURLRequest alloc]initWithURL:webserviceurl];
  12. }else{
  13. [request setURL:webserviceurl];
  14. }
  15.  
  16. NSString *msglength = [NSString stringWithFormat:@"%d", fullsoapMessage.length];
  17. [request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
  18. [request addValue:soapAction1 forHTTPHeaderField:@"SOAPAction"];
  19. [request addValue:msglength forHTTPHeaderField:@"Content-Length"];
  20. [request setHTTPMethod:@"POST"];
  21. [request setHTTPBody:[fullsoapMessage dataUsingEncoding:NSUTF8StringEncoding]];
  22. [request setTimeoutInterval:10000];
  23.  
  24. NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
  25. if (conn) {
  26. webData = [[NSMutableData alloc] init];
  27. }else{
  28. if(IS_DEBUG)
  29. NSLog(@"Connection is NULL");
  30. }
  31. }
  32.  
  33.  
  34. -(BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
  35.  
  36. return YES;
  37.  
  38. }
  39.  
  40.  
  41.  
  42. -(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
  43.  
  44.  
  45.  
  46. if ([challenge previousFailureCount] == 0)
  47.  
  48. {
  49.  
  50. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  51.  
  52. NSString *username = [userDefaults valueForKey:KEY_ADMIN_USERNAME];
  53.  
  54. NSString *password = [userDefaults valueForKey:KEY_ADMIN_PASSWORD];
  55.  
  56.  
  57.  
  58. NSURLCredential *newCredential;
  59.  
  60. newCredential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceNone];
  61.  
  62. [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
  63.  
  64. } else {
  65.  
  66. [[challenge sender] cancelAuthenticationChallenge:challenge];
  67.  
  68. }
  69. }
  70.  
  71. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  72. NSString *username = [userDefaults valueForKey:KEY_ADMIN_USERNAME];
  73. NSString *password = [userDefaults valueForKey:KEY_ADMIN_PASSWORD];
  74. NSString *authStr = [NSString stringWithFormat:@"%@:%@",strUserName,strAPIKey];
  75. NSData *authData = [authStr dataUsingEncoding:NSUTF8StringEncoding];
  76. NSString *authValue = [NSString stringWithFormat:@"Basic %@", [authData base64EncodedStringWithOptions:0]];
  77. [request setValue:authValue forHTTPHeaderField:@"Authorization"];
Add Comment
Please, Sign In to add comment