이 방법을 사용하여 내 서버에 게시물 요청을 보내고 데이터를에 저장하지만 데이터가 데이터베이스에 저장된 경우 일부 문자가 누락 될 수 있습니다. 예를 들어이 문자열이 있습니다. "예를 포스트 ++ 요청 ++" + 더하기 기호 누락으로 데이터베이스 문자열 변경 "예를 POST 요청"을 받았을 때 여기 내 코드http 게시 요청을 보낼 때 오류가 발생합니다
엑스 코드입니다
NSString *STR = @"mystring=example post ++ request ++";
NSData *PostData = [STR dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://MySiteUrl.com/example.php"]];
[request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:PostData];
[request setHTTPMethod:@"POST"];
NSError *error = nil;
NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
PHP 코드
$STR = $_POST['mystring'];
header ('Content-Type: text/html; charset=UTF-8');
$con = mysql_connect("localhost","xxxxxx","xxxx");
mysql_select_db("xxxxxxx", $con);
mysql_query("SET NAMES utf8");
$STR = trim($STR);
mysql_query("INSERT INTO `xxxxxxx`.`table` (`id`, `mystring`) VALUES (NULL, '$STR');");
** 경고 ** ** [** 비추천 ** 데이터베이스 API] (http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql)를 사용하고 있습니다. -functions-in-php) [현대 대체] (http://php.net/manual/en/mysqlinfo.api.choosing.php)를 사용해야합니다. 또한 ** [SQL 주입 공격] (http://bobby-tables.com) **에 취약합니다 ** 현대적인 API로 인해 [방어] (http://stackoverflow.com/questions/60174/)가 쉬워집니다. how-can-i-prevent-sql-injection-in-php)을 사용하지 마십시오. –