本文整理汇总了C++中gd::String::ToUTF8方法的典型用法代码示例。如果您正苦于以下问题:C++ String::ToUTF8方法的具体用法?C++ String::ToUTF8怎么用?C++ String::ToUTF8使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gd::String
的用法示例。
在下文中一共展示了String::ToUTF8方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SendHttpRequest
void GD_API SendHttpRequest(const gd::String & host, const gd::String & uri, const gd::String & body,
const gd::String & method, const gd::String & contentType, gd::Variable & responseVar)
{
// Separate the host and the port number
auto hostInfo = host.Split(U':');
if(hostInfo.size() < 2)
return; //Invalid address (there should be two elements: "http" and "//the.domain.com")
// Create Http
sf::Http http;
http.setHost(hostInfo[0].ToUTF8() + ":" + hostInfo[1].ToUTF8(), hostInfo.size() > 2 ? hostInfo[2].To<unsigned short>() : 0);
// Create request
sf::Http::Request request;
request.setMethod(method == "POST" ? sf::Http::Request::Post : sf::Http::Request::Get);
request.setField("Content-Type", contentType.empty() ? "application/x-www-form-urlencoded" : contentType.ToUTF8());
request.setUri(uri.ToUTF8());
request.setBody(body.ToUTF8());
// Send request & Get response
sf::Http::Response response = http.sendRequest(request);
if (response.getStatus() == sf::Http::Response::Ok)
{
responseVar.SetString(gd::String::FromUTF8(response.getBody()));
}
//else request failed.
}
示例2: DownloadFile
void GD_API DownloadFile( const gd::String & host, const gd::String & uri, const gd::String & outputfilename )
{
// Separate the host and the port number
auto hostInfo = host.Split(U':');
if(hostInfo.size() < 2)
return; //Invalid address (there should be two elements: "http" and "//the.domain.com")
// Create Http
sf::Http http;
http.setHost(hostInfo[0].ToUTF8() + ":" + hostInfo[1].ToUTF8(), hostInfo.size() > 2 ? hostInfo[2].To<unsigned short>() : 0);
// Create request
sf::Http::Request Request;
Request.setMethod(sf::Http::Request::Get);
Request.setUri(uri.ToUTF8());
// Send request & Get response
sf::Http::Response datas = http.sendRequest(Request);
ofstream ofile(outputfilename.ToLocale().c_str(), ios_base::binary);
if ( ofile.is_open() )
{
ofile.write(datas.getBody().c_str(),datas.getBody().size());
ofile.close();
return;
}
cout << "Downloading file : Unable to open output file " << outputfilename;
return;
}
示例3: WriteToFile
bool NativeFileSystem::WriteToFile(const gd::String & filename, const gd::String & content)
{
std::ofstream file( filename.ToLocale().c_str() );
if ( file.is_open() ) {
file << content.ToUTF8();
file.close();
return true;
}
return false;
}