ボタンをクリックすると、JSONポストメソッドを呼び出してデータをサーバーデータベースに保存するサーバーAPIメソッドを渡すアプリケーションがあります.ここでは、携帯電話番号と緊急事態をサーバーデータベースに保存しています.私の携帯電話番号は文字列形式です.私の携帯電話番号文字列変数では、私の携帯電話番号は「+90-9491491411」という形式で保存されています. - データベースに no を送信しますが、サーバー データベースに問題があります + 入力しているモバイルが入力されていません。
-(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
{
}
}
//私の携帯電話番号と緊急番号の変数では、「+91986444711」という形式になっていますが、値がサーバー データベースに入力されると + が削除されます。