我在使用Poco库时遇到了麻烦.我需要一个简单的解决方案来使编译更容易.pkg-configPoco库是否有任何文件可用于我们的make文件?或任何替代解决方案?
目前我使用的是Ubuntu GNU/Linux.
我正在尝试在我的应用程序中使用poco库,但我不知道如何将Poco库链接到它.实际上我不知道应该将多少个库链接到应用程序.我想知道是否有一种简单的方法可以做到,例如使用pkg-config文件,就像我们一样gtkmm,例如:
g++ prog.cc `pkg-config --gtkmm-2.4 --libs --cflags` -o prog
Run Code Online (Sandbox Code Playgroud)
并且pkg-config程序将适当的libs和头文件附加到我们的命令中.
我用C++编程已经有一段时间了,现在我正在努力使用这个Poco库,我正在尝试添加一些HTTP请求.
首先,我在哪里可以添加poco文件?
其次,我已经阅读了一些关于命令提示符并运行将编译文件的脚本,但我必须给它一个参数,这是我的visual studio版本,选择是从70到110.我怎么知道我应该找到哪一个使用?
如果有人能为我提供一步一步的指导,我真的很感激.
谢谢.
我想使用一些跨平台的C++库来启动,停止和获取进程的标准输出.我发现并且我想使用C++ POCO库:这些好吗?
什么是最好的选择?我使用Boost并且他们有Boost Process,但不是官方发布和AFAIK的一部分它不会很快(发展在2008年停止).你能告诉我一下这个POCO lib或其他吗?
这两个代码示例是否相同?
Poco::ProcessHandle::PID ProcessRunner::processId() const
{
Poco::ProcessHandle::PID pid = 0;
mMutex.lock();
pid = mPID;
mMutex.unlock();
return pid;
}
Run Code Online (Sandbox Code Playgroud)
,
Poco::ProcessHandle::PID ProcessRunner::processId() const
{
Poco::ScopedLock<Poco::Mutex> lock(mMutex);
return mPID;
}
Run Code Online (Sandbox Code Playgroud)
在我的测试代码中看起来像线程安全.我可以Poco::Logger在多线程程序中使用吗?
static Poco::Logger *pLogger;
class MyRunnable : public Poco::Runnable {
private:
std::string _name;
Poco::Random _rnd;
public:
void setName(std::string name) {
_name = name;
}
void run() {
for (int i=0; i<200; i++) {
pLogger->information("info from: " + _name);
_rnd.seed(_rnd.next(65532) * _name.size());
Poco::Thread::sleep(_rnd.next(13) + 1);
}
}
};
Run Code Online (Sandbox Code Playgroud)
这里是测试主要:
int
main ( int argc, char *argv[] )
{
Poco::Thread thr1, thr2, thr3;
MyRunnable *pMyR1 = new MyRunnable(),
*pMyR2 = new MyRunnable(),
*pMyR3 = new MyRunnable();
pMyR1->setName("r1");
pMyR2->setName("ra2");
pMyR3->setName("runable3");
Poco::FormattingChannel …Run Code Online (Sandbox Code Playgroud) 我看不到用Poco的 Poco::Util::Application类和相关的方法来支持位置命令行参数Poco::Util::OptionProcessor.位置参数是命令行上的未命名参数,在所有其他选项之后结束,如下所示:
someprogram -b --what=121 filename.bin
Run Code Online (Sandbox Code Playgroud)
在该示例中,filename.bin是位置参数,它没有名称,但是在所有命名参数之后的第一个位置参数.Boost的program_options支持这一点,我发现很难相信Poco没有,但我发现如何根据源和文档来支持它.
Poco支持这个吗?
我正在尝试使用Qt Creator中的poco库和poco附带的一个示例,我已经在Visual Studio 2012中使用它,但我在Qt Creator中不断出现构建错误.我的lib路径中有.dll和.lib.
这是我的.pro文件
TEMPLATE = app
CONFIG += console
CONFIG -= qt
SOURCES += main.cpp
INCLUDEPATH += C:\Users\justin\Downloads\poco-1.4.6\Net\include
INCLUDEPATH += C:\Users\justin\Downloads\poco-1.4.6\Foundation\include
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -lPocoFoundation
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -lPocoFoundationd
INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/
win32:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/lib/PocoFoundation.lib
else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/lib/PocoFoundationd.lib
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -lPocoNet
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -lPocoNetd
INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/
win32:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/lib/PocoNet.lib
else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/lib/PocoNetd.lib …Run Code Online (Sandbox Code Playgroud) 我正在使用boost属性树迭代XML文档并将结果存储在结构中.我遇到的问题是我只能访问第一个"项目"节点,无法访问第二个"项目"节点.我希望有人能指出我犯了错误的地方.
我的程序输出看起来像这样(你可以看到项目丢失..没有显示cookie2,candy2或chocolate2项目):
jar : snAcks
snack : coOkie
item : cooKie1
snack : canDy
item : caNdy1
snack : cHocolate
item : choColate1
Run Code Online (Sandbox Code Playgroud)
这是xml文件:
<root>
<jar name="snAcks">
<snack name="coOkie">
<item name="cooKie1"></item>
<item name="cookIe2"></item>
</snack>
<snack name="canDy">
<item name="caNdy1"></item>
<item name="candY2"></item>
</snack>
<snack name="cHocolate">
<item name="choColate1"></item>
<item name="chocOlate2"></item>
</snack>
</jar>
</root>
Run Code Online (Sandbox Code Playgroud)
这是源代码:
void parse_xml( boost::property_tree::iptree const& pt )
{
BOOST_FOREACH( boost::property_tree::iptree::value_type const& v, pt.get_child("root.jar") )
{
// Show jar
if ( boost::iequals( v.first, "<xmlattr>" ) )
{
std::cout << "jar : …Run Code Online (Sandbox Code Playgroud) AutoPtr<SplitterChannel> splitterChannel(new SplitterChannel());
AutoPtr<Channel> consoleChannel(new ConsoleChannel());
AutoPtr<Channel> fileChannel(new FileChannel("Arcanite.log"));
AutoPtr<FileChannel> rotatedFileChannel(new FileChannel("Arcanite_R.log"));
rotatedFileChannel->setProperty("rotation", "100");
rotatedFileChannel->setProperty("archive", "timestamp");
splitterChannel->addChannel(consoleChannel);
splitterChannel->addChannel(fileChannel);
splitterChannel->addChannel(rotatedFileChannel);
//"%d-%m-%Y %H:%M:%S: %t"
AutoPtr<Formatter> formatter(new PatternFormatter("%d-%m-%Y %H:%M:%S %s: %t"));
AutoPtr<Channel> formattingChannel(new FormattingChannel(formatter, splitterChannel));
Logger& sLog = Logger::create("LogChan", formattingChannel, Message::PRIO_TRACE);
Run Code Online (Sandbox Code Playgroud)
我已经在多个类中编写了我想用于服务器的记录器。我该如何适应这一点?这可能是基本的C ++,但我似乎错过了几节课:P
不知怎的,我发送请求,但内容仍然看起来很奇怪,似乎它没有被解码,但响应包含以下内容:内容编码:gzip
我试图手动解码响应,但那没有用.谢谢您帮忙 :)
void Client::load_login_page()
{
using namespace Poco;
using namespace Poco::Net;
URI uri(constants::url::main_url);
//HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPClientSession session("127.0.0.1", 8888);//Support Fiddler
std::string path(uri.getPathAndQuery());
if (path.empty())
path = "/";
// send request
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
req.set("User-Agent",constants::url::user_agent);
req.add("Accept", "text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/ x-xbitmap, */*;q=0.1");
req.add("Accept-Encoding","gzip,deflate");
req.setHost(uri.getHost(),uri.getPort());
session.sendRequest(req);
// get response
HTTPResponse res;
std::cout << res.getStatus() << " " << res.getReason() << std::endl;
std::cout << res.getContentType() << std::endl;
auto iter = res.begin();
while(iter != res.end())
{
std::cout << …Run Code Online (Sandbox Code Playgroud) 我是POCO的新用户,可以在HTTP :: Request之后获得HTTP响应.
顺便说一句,如何使用一些参数创建HTTP请求?例如,我想设置URI,http://xxxx/index.html?name = hoge&id = fuga&data = foo.
当然我知道如果我直接设置这个uri是可能的.但我想在下面实现这一点.有谁知道这种方式?
URI uri("http://xxx/index.html");
uri.setParam("name", "hoge");
uri.setParam("id", "fuga");
uri.setParam("data", "foo");
Run Code Online (Sandbox Code Playgroud) 我正在使用一个简单的Get请求来从服务器获取通知.我希望请求持续到服务器收到响应(可能是1到9个小时).但我面临2分钟内请求超时的问题.我将会话和请求都设置为"keepalive".但它没有帮助.我也尝试过使用setKeepAliveTimeout并给它一个很大的值.但这也没有改变任何东西.以下是我使用的代码:
try{
//Prepare request
Poco::URI uri(url);
const Poco::Net::Context::Ptr context = new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, "", "", "", Poco::Net::Context::VERIFY_NONE, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort(), context);
session.setKeepAlive(true);
// prepare path
std::string path(uri.getPathAndQuery());
if (path.empty())
{
path = "/";
}
// send request
Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_GET, path, Poco::Net::HTTPMessage::HTTP_1_1);
req.setKeepAlive(true);
session.sendRequest(req);
// Get response
Poco::Net::HTTPResponse res;
//Get status code
statusCode = res.getStatus());
//Get status
status = res.getReason();
//Get body
std::istream &inStream = session.receiveResponse(res);
std::ostringstream outStringStream;
outStringStream << inStream.rdbuf();
response = outStringStream.str();
}
catch(Poco::Exception& exception)
{
cout<<exception.displayText(); …Run Code Online (Sandbox Code Playgroud) poco-libraries ×11
c++ ×10
boost ×1
http-get ×1
httprequest ×1
linux ×1
logging ×1
mutex ×1
opencv ×1
qt ×1
ubuntu-9.10 ×1
xml ×1