Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -(void)getResponseArray:(NSString *)urlstring SoapMessage:(NSString *)soapMessage SoapAction:(NSString *)soapAction1
- {
- self.urlString = urlstring;
- 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];
- if(IS_DEBUG)
- NSLog(@"The request: %@", fullsoapMessage);
- NSURL *webserviceurl = [NSURL URLWithString:urlstring];
- if (request == nil) {
- request = [[NSMutableURLRequest alloc]initWithURL:webserviceurl];
- }else{
- [request setURL:webserviceurl];
- }
- NSString *msglength = [NSString stringWithFormat:@"%d", fullsoapMessage.length];
- [request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
- [request addValue:soapAction1 forHTTPHeaderField:@"SOAPAction"];
- [request addValue:msglength forHTTPHeaderField:@"Content-Length"];
- [request setHTTPMethod:@"POST"];
- [request setHTTPBody:[fullsoapMessage dataUsingEncoding:NSUTF8StringEncoding]];
- [request setTimeoutInterval:10000];
- NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
- if (conn) {
- webData = [[NSMutableData alloc] init];
- }else{
- if(IS_DEBUG)
- NSLog(@"Connection is NULL");
- }
- }
- -(BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
- return YES;
- }
- -(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
- if ([challenge previousFailureCount] == 0)
- {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- NSString *username = [userDefaults valueForKey:KEY_ADMIN_USERNAME];
- NSString *password = [userDefaults valueForKey:KEY_ADMIN_PASSWORD];
- NSURLCredential *newCredential;
- newCredential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceNone];
- [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
- } else {
- [[challenge sender] cancelAuthenticationChallenge:challenge];
- }
- }
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- NSString *username = [userDefaults valueForKey:KEY_ADMIN_USERNAME];
- NSString *password = [userDefaults valueForKey:KEY_ADMIN_PASSWORD];
- NSString *authStr = [NSString stringWithFormat:@"%@:%@",strUserName,strAPIKey];
- NSData *authData = [authStr dataUsingEncoding:NSUTF8StringEncoding];
- NSString *authValue = [NSString stringWithFormat:@"Basic %@", [authData base64EncodedStringWithOptions:0]];
- [request setValue:authValue forHTTPHeaderField:@"Authorization"];
Add Comment
Please, Sign In to add comment