- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有以下代码(现在可以编译,感谢@LokiAstari):
要编译下面这段代码,最简单的方法是下载curlpp ,编译它。然后用g++-mp-4.4(由macport安装)编译以下代码,链接到curl和curlpp。
如果 localhost:8080 不存在,它将崩溃(输出:abort trap
)。将 g++-mp-4.4 更改为 Xcode 4 默认的 g++,它工作正常。
#include <string>
#include <sstream>
#include <iostream>
#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
int main(int, char **)
{
try
{
curlpp::Cleanup myCleanup;
{
std::ostringstream os;
os << curlpp::options::Url("http://localhost:8080/");
}
}
catch( curlpp::RuntimeError &e )
{
std::cout << e.what() << std::endl;
}
catch( curlpp::LogicError &e )
{
std::cout << e.what() << std::endl;
}
return 0;
}
更新:
在 Easy.cpp 中:
void
curlpp::Easy::perform()
{
mCurl->perform(); // The exception come from here. mCurl is a std::auto_ptr<internal::CurlHandle> mCurl;
}
......
std::ostream & operator<<(std::ostream & stream, const curlpp::Easy & request)
{
// Quick clone that doesn't copy options, only the curl handle.
curlpp::Easy r(request.getCurlHandle().clone());
r.setOpt(new curlpp::options::WriteStream(& stream));
r.perform(); // The exception come from here.
return stream;
}
在 CurlHandle.cpp 中:
void CurlHandle::perform()
{
CURLcode code;
code = curl_easy_perform(mCurl);
throwException();
libcurlRuntimeAssert(mErrorBuffer, code); //if we got an error
}
在 Exception.cpp 中:
void curlpp::libcurlRuntimeAssert(const std::string & reason, CURLcode code)
{
curlpp::libcurlRuntimeAssert(reason.c_str(), code);
}
void curlpp::libcurlRuntimeAssert(const char * reason, CURLcode code)
{
if (code != CURLE_OK)
throw curlpp::LibcurlRuntimeError(reason, code);
}
我追到了代码,throw curlpp::LibcurlRuntimeError(reason, code);
,LibcurlRuntimeError
的构造函数没问题,然后throw,然后SIGABRT。
堆栈跟踪:
0 __kill 0 0x7fff8213d0b6
1 abort 0 0x7fff821dd9f6
2 uw_init_context_1 0 0x101663af2
3 _Unwind_Resume 0 0x101663f38
4 operator<< Easy.cpp 118 0x10009b699
5 operator<< Options.cpp 34 0x1000948d8
6 RoleCreationTest::loadPlayerAsyncTestCase rolecreationtest.cpp 147 0x10008c714
7 RoleCreationTest::qt_metacall moc_rolecreationtest.cpp 87 0x1000acab2
8 QMetaMethod::invoke 0 0x1012e6667
最佳答案
各种 MacPorts GCC 4.x 编译器和异常捕获都存在问题,参见示例 GCC bug 42159和 MacPorts bug 25042 .
关于C++ 无法使用 g++-mp-4.4 捕获从 Mac OS 中的 curlpp 抛出的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7983579/
当我编译这段代码时: #include #include #include #include int main() { cURLpp :: Cleanup cleanup; s
Ubuntu 15.04、CLion、LibCurl、curl 版本 - 7.38.00。当我编译这段代码时: #include #include #include #include #inc
我编写了一个 C++ 程序并尝试使用 curlpp 通过 SSL 安全地访问 http 服务器。问题是,我无法链接程序。 操作系统:Ubuntu 15.10 错误: /usr/bin/cmake -E
我已经研究了几个小时(就在今天),所以我真的需要一些帮助。我总是在 Windows 环境中编写代码,因此我尝试将 curlpp 添加到我的 Code::Blocks 项目中。 我下载了 curl-7.
我正在使用 Curlpp 向各种网络服务发送请求以发送和接收数据。到目前为止,它运行良好,因为我只将它用于发送/接收 JSON 数据。 现在我遇到这样一种情况,即 Web 服务以二进制形式返回一个 z
我正在调用带有 JSON 负载的 REST WS 来订阅某些事件。服务器使用 HTTP 代码 201 和 HTTP header 中名为 Location 的字段进行响应,其中包含订阅 ID。 例如,
我目前正在使用 curlpp 执行 HTTP 查询,但 curlpp 报告 URL 中存在非法字符。我已经将 URL 问题缩小到一个从配置文件中读取的变量(一行,它只包含所需的信息)。另一个奇怪的事情
这个问题和另一个相似one, concerning pyCURL 当我使用 CURLpp https://stackoverflow.com/questions/1942719/pycurl-tls-
我正在编写一个下载多个文件的程序(目前只有 2 个)。我试图让它使用 ProgressFunction 回调显示每次下载的进度条。我遇到的问题是我无法找到一种方法来区分两个文件之间的进度。现在它正在两
我正在尝试从 vb.net 过渡到 C++,但我一直坚持这一点。我从 here 下载了 curlpp这让我得到了一个 .dll、.exp 和 .lib 文件。我将包含这 3 个文件的目录添加到项目属性
我正在使用 curlpp 接收响应。我指的是 curlpp 网站的这个例子 http://curlpp.org/index.php/examples/64-example-14 .但是我没有得到响应的
我想使用以下 URL 提取维基百科页面的摘要: https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&ex
我正在尝试使用静态 curlpp 库在 VS2008 中构建一个 C++ 控制台应用程序。代码 - 这是 curlpp 示例 00 - 如下所示: #include "stdafx.h" #inclu
如何从 curlpp 请求中检索响应 cookie? 我想存储 HTTP GET 请求的 PHP session 。这是我当前的代码: void Grooveshark::Connection::pr
下面是使用 curl 的简单 test.c 代码: #include #include int main(){ return 0; } 为了编译这段代码,我使用: gcc t
我想在 curlcpp 和 cmake 的帮助下用 C++ 做一个项目,但我无法编译该项目。 我是 CMakeLists 的新手,很难理解如何添加使项目正常运行所需的内容。我基本上通常会在没有真正理解
我想使用 libcurl 和 cURLpp 向服务器发送一个 http POST 请求。当我尝试编译我的程序时,出现了这些错误。我不认为错误来自 libcurl 或 curlpp,所以我一定做错了什么
我是 C++ 的新手,我正在使用 mingw 编译器。最后一行 #include #include #include .... string url ("http://www.google.co
我正在尝试在我的 Xcode C++ 项目中使用 curlpp,但即使我在项目设置中将库添加到目标,我仍被告知“找不到文件”这一行 #include 我可能做错了什么,但我不确定是什么。我关注了so
我想在我的 C++ 项目中使用 curl/curlpp,所以我使用了命令: brew install curl 和 brew install curlpp 没有问题。因此,为了检查它们是否安装正确,我
我是一名优秀的程序员,十分优秀!