mirror of
https://gitee.com/xia-chu/ZLMediaKit.git
synced 2026-05-06 10:57:50 +08:00
feature:添加http head请求的支持 (#4321)
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
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请求的支持
This commit is contained in:
parent
48fd240817
commit
fd34b5526b
@ -264,7 +264,7 @@ ssize_t HttpClient::onRecvHeader(const char *data, size_t len) {
|
|||||||
_total_body_size = -1;
|
_total_body_size = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_total_body_size == 0) {
|
if (_total_body_size == 0 || _method == "HEAD") {
|
||||||
// 后续没content,本次http请求结束 [AUTO-TRANSLATED:8532172f]
|
// 后续没content,本次http请求结束 [AUTO-TRANSLATED:8532172f]
|
||||||
// There is no content afterwards, this http request ends
|
// There is no content afterwards, this http request ends
|
||||||
onResponseCompleted_l(SockException(Err_success, "The request is successful but has no body"));
|
onResponseCompleted_l(SockException(Err_success, "The request is successful but has no body"));
|
||||||
|
|||||||
27
tests/test_http_head.cpp
Normal file
27
tests/test_http_head.cpp
Normal file
@ -0,0 +1,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;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user