2016-11-16 2 views
1

Я пытаюсь сделать запрос в этом формате, тогда проблема возникает на obj, если у кого-то есть идея решить это, то, пожалуйста, скажите мне, как поразить его в obj NSURL , в то время как этот формат работает, когда класс или obj не находится в формате мыла.Как сделать запрос на мыло в ios с этим

<?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> 
<login xmlns="http://aksmala_idoc/"> 
    <lgn> 
    <Lng>string</Lng> 
    <IMEI>string</IMEI> 
    <Version>string</Version> 
    </lgn> 
</login> 

ответ

0
NSString* msg = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
      "<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/\">\n" 
      "<soap:Body>\n" 
      "<login xmlns=\"http://aksha/app/\">\n" 
      "<Lng>%@</Lng>\n" 
      "<IMEI>%@</IMEI>\n" 
      "<Version>%@</Version>\n" 

      "</login>\n" 
      "</soap:Body>\n" 
      "</soap:Envelope>\n",lon,@"0",devicetype,lat,@"uTgQLrznrZY6z7m17SFqnA==",@"EvSNUlJbFToEsjPmN09UYQ==",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",uniqueIdentifier,version]; 

NSString *messageLength = [NSString stringWithFormat:@"%lu", (unsigned long)[msg length]]; 
[MBProgressHUD showHUDAddedTo:self.view animated:YES]; 

NSURL *requestURL = [NSURL URLWithString:URL]; 
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:requestURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30]; 
[theRequest addValue:Host forHTTPHeaderField:@"Host"]; 
[theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
[theRequest addValue:@"http://aksmala_idoc/login" forHTTPHeaderField:@"SOAPAction"]; 
[theRequest addValue:messageLength forHTTPHeaderField:@"Content-Length"]; 
[theRequest setHTTPMethod:@"POST"]; 
[theRequest setHTTPBody:[msg dataUsingEncoding:NSUTF8StringEncoding]]; 
// sending the request 



AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:theRequest]; 

operation.responseSerializer = [AFHTTPResponseSerializer serializer]; 

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 

    NSString *xml = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; 
    [MBProgressHUD hideHUDForView:self.view animated:YES]; 
    NSLog(@"Take the data master Yoda: %@", xml); 
    NSError *parseError; 
    NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLString:xml error:parseError]; 
    NSLog(@" %@", xmlDictionary); 
    NSDictionary*dict=[xmlDictionary valueForKey:@"soap:Envelope"]; 
    NSDictionary*dict1=[dict valueForKey:@"soap:Body"]; 
    NSDictionary*dict2=[dict1 valueForKey:@"LoginResponse"]; 
    NSDictionary*dict3=[dict2 valueForKey:@"LoginResult"]; 
    // NSArray*textstring=[dict3 valueForKey:@"text"]; 
    /* 
    NSData *data1 = [[dict3 valueForKey:@"text"] dataUsingEncoding:NSUTF8StringEncoding]; 
    NSArray* json = [NSJSONSerialization JSONObjectWithData:data1 options:0 error:nil]; 
    NSDictionary*datadict=[json objectAtIndex:0]; 


    NSString*roleid=[datadict valueForKey:@"role_id"]; 
    //NSString* emp_id = [FBEncryptorAES decryptBase64String:empid keyString:@"5TGB&YHN7UJM(IK<"]; 
    NSString* role_id = [FBEncryptorAES decryptBase64String:roleid keyString:@"5TGB&YHN7UJM(IK<"]; 
    */ 

} failure:^(AFHTTPRequestOperation *operation, NSError * error) { 
    NSLog(@"%@", error.description); 
    [MBProgressHUD hideHUDForView:self.view animated:YES]; 
    UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@"Error" message:@"Wrong Userid or Password" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; 
    [alert show]; 


}]; 

[[NSOperationQueue mainQueue] addOperation:operation];