POCO C++库,HTTPResponse状态错误
POCO C++ Library, HTTPResponse bad status
我试图在Ubuntu Linux上使用POCO C++库从网络流中解压缩文件,但解压缩失败,出现"非法状态"异常。HTTPResponse
的状态和原因是302暂时移动。同时,我可以用浏览器下载并解压缩链接。当HTTPResponse
处于这种状态时,我应该如何处理HTTPClientSession
?
...
HTTPResponse res;
std::istream& rs = h_ses.receiveResponse (res);
if (res.getStatus () != HTTPResponse::HTTP_OK) {
poco_error (logger, "http response status: " + std::to_string (res.getStatus ()) + " " + res.getReason ());
}
if (!rs) {
poco_error (logger, "responese stream is in bad state: " + std::to_string (rs.rdstate()));
}
Decompress dec (rs, target_dir_.native ());
poco_debug (logger, "Unzipping: " + dl + " ...");
dec.EError += Poco::Delegate<Addon_Loader, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &Addon_Loader::on_decompress_error);
dec.decompressAllFiles ();
...
您可以使用HTTPStreamFactory;这里有一个完整的例子:
#include "Poco/URI.h"
#include "Poco/URIStreamOpener.h"
#include "Poco/Net/HTTPStreamFactory.h"
#include "Poco/StreamCopier.h"
#include <iostream>
#include <memory>
using namespace Poco;
using namespace Poco::Net;
int main()
{
URIStreamOpener opener;
opener.registerStreamFactory("http", new HTTPStreamFactory);
URI uri("http://httpbin.org/redirect-to?url=http%3A%2F%2Fexample.com%2F");
std::auto_ptr<std::istream> pStr(opener.open(uri));
StreamCopier::copyStream(*pStr.get(), std::cout);
return 0;
}
如果你必须使用HTTPClientSession,看看HTTPStreamFactory是如何做到的。
在302
响应中,应该有一个指出新位置的头字段。你只需点击该链接即可。
例如,请参阅此链接或维基百科页面,当然还有实际的HTTP 1.1 RFC。
相关文章:
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- C++ 中的编译错误:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 编译问题:在函数"_start"中:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 试图在崇高中奔跑. 错误 已发生: 收集2.exe: 错误: ld 返回 1 退出状态
- collect2:错误:ld 返回 1 个退出状态未定义的引用
- q网络回复 无状态码或错误,但失败
- C++ collect2:错误:ld 返回 1 退出状态
- 找不到 -llibmysqld Collect2.exe:错误:ld 返回 1 退出状态
- 删除使数据处于"错误状态"的默认构造函数的模式?
- 每次我要使用外部资源时,我都会得到:collect2。exe:错误 ld 返回 1 退出状态
- 当出现错误ld return 1退出状态时,如何编译程序
- 无法访问 Arduino 结构字段。错误"退出状态 1。xxxx 不命名类型"
- "Extern"对象问题:错误:Id 返回 1 个退出状态
- 线路抑制状态错误 C4703 可能未初始化的局部指针变量"back"已使用
- c++ (C::B) 错误:ld 返回 1 个退出状态
- 严重性代码说明项目文件行抑制状态错误 C2676 二进制">>":"std::ifstream"
- 如何解决退出状态 1 错误
- C++11期货/承诺中没有状态错误
- Xcode C++游戏状态错误
- POCO C++库,HTTPResponse状态错误