Мне было поручено добавить полную поддержку Unicode в наше программное обеспечение.
Мы используем Curl для отправки запроса на сервер, и я совершенно новичок в Php.
Мы хотим поддержать этот тип электронной почты: 沙发模型@gmail.com < /strong>
я попытался создать акценты с именами и сбоями. Но прежде чем бросить функцию, мне нужно быть на 100% уверенным, что только электронные письма UTF-8 разрешены по всему миру. Поэтому я хочу поддерживать широкие строки, а не только UTF-8. < /P>
Наша таблица базы данных, которая выглядит так:
INSERT INTO `LICENSES_TABLE`(`EMAIL`, `LICENSE_KEYS`, `COMPUTER_CODES`, `IPS`) VALUES ('roberto_沙发模型@hotmail.com', '371C-5BE3-6EF4-9DBC-7F65', 'null', 'null')
< /code>
Я получаю это:
< /p>
wome whole -worry@???@hotmail.com " Поддержать электронные письма Unicode на сервере на основе MySQLI? Здесь, как наше приложение C ++ отправить запрос на сервер < /p>
RequestResult NetWork::sendRequest(const bool isPost, const std::string& relativeUri, const std::string& body) const
{
CURL* handle = curl_easy_init();
if (!handle)
return RequestResult();
/* First set the URL that is about to receive our POST. This URL can
* just as well be a https:// URL if that is what should receive the
* data.
*/
curl_easy_setopt(handle, CURLOPT_URL, ("https://www.mywebsite.com/" + relativeUri).c_str());
// Skip SSL verification.
// Not required when server use a certificate signed by a trusted CA.
// @See: https://stackoverflow.com/questions/56739554/is-https-without-ssl-verification-secure-for-local-application
{
/*
* If you want to connect to a site who isn't using a certificate that is
* signed by one of the certs in the CA bundle you have, you can skip the
* verification of the server's certificate. This makes the connection
* A LOT LESS SECURE.
*
* If you have a CA cert for the server stored someplace else than in the
* default bundle, then the CURLOPT_CAPATH option might come handy for
* you.
*/
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L);
/*
* If the site you're connecting to uses a different host name that what
* they have mentioned in their server certificate's commonName (or
* subjectAltName) fields, libcurl will refuse to connect. You can skip
* this check, but this will make the connection less secure.
*/
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L);
}
// Specify the request type
curl_easy_setopt(handle, CURLOPT_POST, (int)isPost);
// Specify the body
curl_easy_setopt(handle, CURLOPT_POSTFIELDS, body.c_str());
// Specify the write callbaks
RequestResult requestResult;
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &requestResult.res);
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, CurlWrite_CallbackFunc_StdString);
// Perform the request
const CURLcode res = curl_easy_perform(handle);
// Check result
if (res == CURLE_OK)
{
long http_code = 0;
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &http_code);
requestResult.success = http_code < 400;
}
else
{
_TRACE(requestResult.res);
}
// Cleanup
curl_easy_cleanup(handle);
return requestResult;
}
Как вы можете видеть в объявлении, тело - это std :: string, а не широкая строка . Я не знаю, как это волшебно работает, но если электронная почта (roberto_ 沙发模型@hotmail.com), то тело SendRequest содержит (Roberto_æ² ™ ő模 Как h Hotmail.com). Запрос отправляется, и сервер понимает, что реальная электронная почта (roberto_ 沙发模型@hotmail.com)
Мне было поручено добавить полную поддержку Unicode в наше программное обеспечение.
Мы используем Curl для отправки запроса на сервер, и я совершенно новичок в Php.
Мы хотим поддержать этот тип электронной почты: [b] 沙发模型@gmail.com < /strong>
я попытался создать акценты с именами и сбоями. Но прежде чем бросить функцию, мне нужно быть на 100% уверенным, что только электронные письма UTF-8 разрешены по всему миру. Поэтому я хочу поддерживать широкие строки, а не только UTF-8. < /P> Наша таблица базы данных, которая выглядит так:
Зарегистрировано: [/b] [code]$result = \mysqli_query($this->m_conn, "INSERT INTO ".self::TABLE_NAME."(EMAIL, LICENSE_KEYS, COMPUTER_CODES, IPS) VALUES ('$email', '$license', 'null', 'null')"); if (!$result) Logger::ExitWithMessage($email, "DB: unable to insert user. SQL error:". mysqli_error($this->m_conn)); [/code] [b] Если я попытаюсь добавить китайского пользователя в нашу тестовую таблицу: [/b] [code]$robertoEmail = "roberto_沙发模型@hotmail.com"; $robertoLicense = "371C-5BE3-6EF4-9DBC-7F65";
$result = \mysqli_query($this->m_conn, "INSERT INTO ".self::TABLE_NAME."(EMAIL, LICENSE_KEYS, COMPUTER_CODES, IPS) VALUES ('$robertoEmail', '$robertoLicense', 'null', 'null')"); if (!$result) Logger::ExitWithMessage($robertoEmail, "DB: unable to insert user. SQL error:". mysqli_error($this->m_conn)); < /code> Когда я проверяю таблицу, я получаю это «roberto_æ² ™ ő模варла‹@hotmail.com »в качестве электронной почты:
< /> < /> < /> < /> < /> < /pr /pm.net.net/v82nyvko.png ' База данных сломана. [b] Но что -то странное [/b] я запрашиваю таблицу с пользователем Roberto (roberto_ 沙发模型@hotmail.com) Это работает: $robertoEmail = "roberto_沙发模型@hotmail.com";
$query = \mysqli_query($this->m_conn, "SELECT * FROM `". self::TABLE_NAME. "` WHERE EMAIL='$robertoEmail'"); if (!$query) Logger::ExitWithMessage($email, "DB: Can't select. SQL error:". mysqli_error($this->m_conn));
if (!$user) { error_log("GetUser failed"); return; }
// Everything worked! [/code] [b] еще более странно, если я попытаюсь вручную добавить Роберто в таблицу [/b]: [code] INSERT INTO `LICENSES_TABLE`(`EMAIL`, `LICENSE_KEYS`, `COMPUTER_CODES`, `IPS`) VALUES ('roberto_沙发模型@hotmail.com', '371C-5BE3-6EF4-9DBC-7F65', 'null', 'null') < /code> Я получаю это:
< /p> wome whole -worry@???@hotmail.com " Поддержать электронные письма Unicode на сервере на основе MySQLI? Здесь, как наше приложение C ++ отправить запрос на сервер < /p> RequestResult NetWork::sendRequest(const bool isPost, const std::string& relativeUri, const std::string& body) const { CURL* handle = curl_easy_init(); if (!handle) return RequestResult();
/* First set the URL that is about to receive our POST. This URL can * just as well be a https:// URL if that is what should receive the * data. */ curl_easy_setopt(handle, CURLOPT_URL, ("https://www.mywebsite.com/" + relativeUri).c_str());
// Skip SSL verification. // Not required when server use a certificate signed by a trusted CA. // @See: https://stackoverflow.com/questions/56739554/is-https-without-ssl-verification-secure-for-local-application { /* * If you want to connect to a site who isn't using a certificate that is * signed by one of the certs in the CA bundle you have, you can skip the * verification of the server's certificate. This makes the connection * A LOT LESS SECURE. * * If you have a CA cert for the server stored someplace else than in the * default bundle, then the CURLOPT_CAPATH option might come handy for * you. */ curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L);
/* * If the site you're connecting to uses a different host name that what * they have mentioned in their server certificate's commonName (or * subjectAltName) fields, libcurl will refuse to connect. You can skip * this check, but this will make the connection less secure. */ curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L); }
// Specify the request type curl_easy_setopt(handle, CURLOPT_POST, (int)isPost);
// Specify the body curl_easy_setopt(handle, CURLOPT_POSTFIELDS, body.c_str());
// Perform the request const CURLcode res = curl_easy_perform(handle);
// Check result if (res == CURLE_OK) { long http_code = 0; curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &http_code); requestResult.success = http_code < 400; } else { _TRACE(requestResult.res); }
// Cleanup curl_easy_cleanup(handle);
return requestResult; } [/code] [b] Как вы можете видеть в объявлении, тело - это std :: string, а не широкая строка [/b]. Я не знаю, как это волшебно работает, но если электронная почта (roberto_ 沙发模型@hotmail.com), то тело SendRequest содержит (Roberto_æ² ™ ő模 Как h Hotmail.com). Запрос отправляется, и сервер понимает, что реальная электронная почта (roberto_ 沙发模型@hotmail.com)