I have an application where, when I click a button, I pass my api method to the server, which calls the JSON mailing method and stores the data in the server database. Here I save the mobile number and emergency assistance is not in the server database. My mobile number is in string format. In my mobile number variable, my mobile number gets saved, which is in this format "+ 90-9491491411". I enter +, and then the code, and then - and then the number, but when I send to the server database I delete - and sends no to the database, but the problem in my server + mobile database is not entered, which I enter. What could be the problem. I use the POST method to send a request. This is my code.
-(void)sendRequest { NSString *newstring = txtMobile.text; mobileValue = [newstring stringByReplacingOccurrencesOfString:@"-" withString:@""]; NSLog(@"%@",mobileValue); NSString *newString1 = txtemergencyprovider.text; emergencyNumber = [newString1 stringByReplacingOccurrencesOfString:@"-" withString:@""]; NSLog(@"%@",emergencyNumber); if ([txtEmail.text isEqualToString:@""]) { post = [NSString stringWithFormat:@"CommandType=new&ApplicationType=%d&FullName=%@&Mobile=%@&EmergencymobileNumber=%@&Latitude=%f&Longitude=%f&City=%@&MobileModel=Apple",applicationtype,txtFullname.text,mobileValue,emergencyNumber,latitude,longitude,txtCity.text]; NSLog(@"%@",post); } else { post = [NSString stringWithFormat:@"CommandType=new&ApplicationType=%d&FullName=%@&Mobile=%@&EmergencymobileNumber=%@&Latitude=%f&Longitude=%f&City=%@&EmailAddress=%@&MobileModel=Apple",applicationtype,txtFullname.text,mobileValue,emergencyNumber,latitude,longitude,txtCity.text,txtEmail.text]; NSLog(@"%@",post); } NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; NSLog(@"%@",postLength); NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:@"http://myapi?RequestType=NEW"]]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:postData]; NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; if (theConnection) { webData = [[NSMutableData data] retain]; NSLog(@"%@",webData); } else { } }
// In my mobile number and variable number, emhgency my no is in this format "+91986444711", but when the value is entered into the server + database, it is deleted. What could be the problem.
Rani
source share