forked from ZLMediaKit/ZLMediaKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_http_head.cpp
More file actions
27 lines (23 loc) · 808 Bytes
/
Copy pathtest_http_head.cpp
File metadata and controls
27 lines (23 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#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;
}