简体   繁体   中英

how to make a soap request in ios with this

I am trying to make request in this format then is problem is occurring on the obj ,if anyone have idea to solve this then please tell me how to hit it in obj by NSURL . while this format work when like class or obj is not be in soap format.

<?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>

  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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM