mirror of
https://gitee.com/xia-chu/ZLMediaKit.git
synced 2026-05-06 10:57:50 +08:00
Some checks failed
Android / build (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docker / build (push) Has been cancelled
Linux / build (push) Has been cancelled
macOS / build (push) Has been cancelled
Windows / build (push) Has been cancelled
添加http head请求的支持
27 lines
808 B
C++
27 lines
808 B
C++
#include "Http/HttpRequester.h"
|
|
|
|
int main() {
|
|
auto requester = std::make_shared<mediakit::HttpRequester>();
|
|
requester->setMethod("HEAD");
|
|
|
|
requester->startRequester(
|
|
"http://baidu.com",
|
|
|
|
[](const toolkit::SockException &ex, const mediakit::Parser &parser) {
|
|
if (ex) {
|
|
PrintI("HEAD请求失败: %s", ex.what());
|
|
return;
|
|
}
|
|
|
|
// 检查HTTP状态码
|
|
if (parser.status() != "200") {
|
|
PrintI("HEAD请求返回错误状态: %s", parser.status().c_str());
|
|
return;
|
|
}
|
|
for (auto &header : parser.getHeader()) {
|
|
PrintI("key=%s, val=%s", header.first.c_str(), header.second.c_str());
|
|
}
|
|
});
|
|
getchar();
|
|
return 0;
|
|
} |