本文整理汇总了C++中url::Ptr::SetQuery方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::SetQuery方法的具体用法?C++ Ptr::SetQuery怎么用?C++ Ptr::SetQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类url::Ptr
的用法示例。
在下文中一共展示了Ptr::SetQuery方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExecuteScript
void ApiClient::ExecuteScript(const String& session, const String& command, bool sandboxed,
const ExecuteScriptCompletionCallback& callback) const
{
Url::Ptr url = new Url();
url->SetScheme("https");
url->SetHost(m_Connection->GetHost());
url->SetPort(m_Connection->GetPort());
url->SetPath({ "v1", "console", "execute-script" });
std::map<String, std::vector<String> > params;
params["session"].push_back(session);
params["command"].push_back(command);
params["sandboxed"].emplace_back(sandboxed ? "1" : "0");
url->SetQuery(params);
try {
std::shared_ptr<HttpRequest> req = m_Connection->NewRequest();
req->RequestMethod = "POST";
req->RequestUrl = url;
req->AddHeader("Authorization", "Basic " + Base64::Encode(m_User + ":" + m_Password));
req->AddHeader("Accept", "application/json");
m_Connection->SubmitRequest(req, std::bind(ExecuteScriptHttpCompletionCallback, _1, _2, callback));
} catch (const std::exception&) {
callback(boost::current_exception(), Empty);
}
}
示例2: AutoCompleteScript
/**
* Executes the auto completion script via HTTP and returns HTTP and user errors.
*
* @param session Local session handler.
* @param command The auto completion string.
* @param sandboxed Whether to run this sandboxed.
* @return Result value, also contains user errors.
*/
Array::Ptr ConsoleCommand::AutoCompleteScript(const String& session, const String& command, bool sandboxed)
{
/* Extend the url parameters for the request. */
l_Url->SetPath({ "v1", "console", "auto-complete-script" });
l_Url->SetQuery({
{"session", session},
{"command", command},
{"sandboxed", sandboxed ? "1" : "0"}
});
Dictionary::Ptr jsonResponse = SendRequest();
/* Extract the result, and handle user input errors too. */
Array::Ptr results = jsonResponse->Get("results");
Array::Ptr suggestions;
if (results && results->GetLength() > 0) {
Dictionary::Ptr resultInfo = results->Get(0);
if (resultInfo->Get("code") >= 200 && resultInfo->Get("code") <= 299) {
suggestions = resultInfo->Get("suggestions");
} else {
String errorMessage = resultInfo->Get("status");
BOOST_THROW_EXCEPTION(ScriptError(errorMessage));
}
}
return suggestions;
}
示例3: GetObjects
void ApiClient::GetObjects(const String& pluralType, const ObjectsCompletionCallback& callback,
const std::vector<String>& names, const std::vector<String>& attrs, const std::vector<String>& joins, bool all_joins) const
{
Url::Ptr url = new Url();
url->SetScheme("https");
url->SetHost(m_Connection->GetHost());
url->SetPort(m_Connection->GetPort());
std::vector<String> path;
path.push_back("v1");
path.push_back("objects");
path.push_back(pluralType);
url->SetPath(path);
std::map<String, std::vector<String> > params;
for (const String& name : names) {
params[pluralType.ToLower()].push_back(name);
}
for (const String& attr : attrs) {
params["attrs"].push_back(attr);
}
for (const String& join : joins) {
params["joins"].push_back(join);
}
params["all_joins"].push_back(all_joins ? "1" : "0");
url->SetQuery(params);
try {
boost::shared_ptr<HttpRequest> req = m_Connection->NewRequest();
req->RequestMethod = "GET";
req->RequestUrl = url;
req->AddHeader("Authorization", "Basic " + Base64::Encode(m_User + ":" + m_Password));
req->AddHeader("Accept", "application/json");
m_Connection->SubmitRequest(req, boost::bind(ObjectsHttpCompletionCallback, _1, _2, callback));
} catch (const std::exception& ex) {
callback(boost::current_exception(), std::vector<ApiObject::Ptr>());
}
}
示例4: ExecuteScript
/**
* Executes the DSL script via HTTP and returns HTTP and user errors.
*
* @param session Local session handler.
* @param command The DSL string.
* @param sandboxed Whether to run this sandboxed.
* @return Result value, also contains user errors.
*/
Value ConsoleCommand::ExecuteScript(const String& session, const String& command, bool sandboxed)
{
/* Extend the url parameters for the request. */
l_Url->SetPath({"v1", "console", "execute-script"});
l_Url->SetQuery({
{"session", session},
{"command", command},
{"sandboxed", sandboxed ? "1" : "0"}
});
Dictionary::Ptr jsonResponse = SendRequest();
/* Extract the result, and handle user input errors too. */
Array::Ptr results = jsonResponse->Get("results");
Value result;
if (results && results->GetLength() > 0) {
Dictionary::Ptr resultInfo = results->Get(0);
if (resultInfo->Get("code") >= 200 && resultInfo->Get("code") <= 299) {
result = resultInfo->Get("result");
} else {
String errorMessage = resultInfo->Get("status");
DebugInfo di;
Dictionary::Ptr debugInfo = resultInfo->Get("debug_info");
if (debugInfo) {
di.Path = debugInfo->Get("path");
di.FirstLine = debugInfo->Get("first_line");
di.FirstColumn = debugInfo->Get("first_column");
di.LastLine = debugInfo->Get("last_line");
di.LastColumn = debugInfo->Get("last_column");
}
bool incompleteExpression = resultInfo->Get("incomplete_expression");
BOOST_THROW_EXCEPTION(ScriptError(errorMessage, di, incompleteExpression));
}
}
return result;
}