整理http相关代码

This commit is contained in:
ziyue
2021-09-30 16:10:09 +08:00
parent a548fcd709
commit 15edbeac3e
11 changed files with 251 additions and 209 deletions

View File

@@ -76,9 +76,7 @@ int main(int argc, char *argv[]) {
//开启请求该api会返回当前主机外网ip等信息
requesterGet->startRequester("http://pv.sohu.com/cityjson?ie=utf-8",//url地址
[](const SockException &ex, //网络相关的失败信息,如果为空就代表成功
const string &status, //http回复的状态码比如说200/404
const HttpClient::HttpHeader &header, //http回复头
const string &strRecvBody) { //http回复body
const Parser &parser) { //http回复body
DebugL << "=====================HttpRequester GET===========================";
if (ex) {
//网络相关的错误
@@ -86,12 +84,12 @@ int main(int argc, char *argv[]) {
} else {
//打印http回复信息
_StrPrinter printer;
for (auto &pr: header) {
for (auto &pr: parser.getHeader()) {
printer << pr.first << ":" << pr.second << "\r\n";
}
InfoL << "status:" << status << "\r\n"
InfoL << "status:" << parser.Url() << "\r\n"
<< "header:\r\n" << (printer << endl)
<< "\r\nbody:" << strRecvBody;
<< "\r\nbody:" << parser.Content();
}
});
@@ -114,9 +112,7 @@ int main(int argc, char *argv[]) {
//开启请求
requesterPost->startRequester("http://fanyi.baidu.com/langdetect",//url地址
[](const SockException &ex, //网络相关的失败信息,如果为空就代表成功
const string &status, //http回复的状态码比如说200/404
const HttpClient::HttpHeader &header, //http回复头
const string &strRecvBody) { //http回复body
const Parser &parser) { //http回复body
DebugL << "=====================HttpRequester POST==========================";
if (ex) {
//网络相关的错误
@@ -124,12 +120,12 @@ int main(int argc, char *argv[]) {
} else {
//打印http回复信息
_StrPrinter printer;
for (auto &pr: header) {
for (auto &pr: parser.getHeader()) {
printer << pr.first << ":" << pr.second << "\r\n";
}
InfoL << "status:" << status << "\r\n"
InfoL << "status:" << parser.Url() << "\r\n"
<< "header:\r\n" << (printer << endl)
<< "\r\nbody:" << strRecvBody;
<< "\r\nbody:" << parser.Content();
}
});
@@ -153,9 +149,7 @@ int main(int argc, char *argv[]) {
//开启请求
requesterUploader->startRequester("http://fanyi.baidu.com/langdetect",//url地址
[](const SockException &ex, //网络相关的失败信息,如果为空就代表成功
const string &status, //http回复的状态码比如说200/404
const HttpClient::HttpHeader &header, //http回复头
const string &strRecvBody) { //http回复body
const Parser &parser) { //http回复body
DebugL << "=====================HttpRequester Uploader==========================";
if (ex) {
//网络相关的错误
@@ -163,12 +157,12 @@ int main(int argc, char *argv[]) {
} else {
//打印http回复信息
_StrPrinter printer;
for (auto &pr: header) {
for (auto &pr: parser.getHeader()) {
printer << pr.first << ":" << pr.second << "\r\n";
}
InfoL << "status:" << status << "\r\n"
InfoL << "status:" << parser.Url() << "\r\n"
<< "header:\r\n" << (printer << endl)
<< "\r\nbody:" << strRecvBody;
<< "\r\nbody:" << parser.Content();
}
});