Limit the HTTP body content to dump/log.

This commit is contained in:
Chunting Gu
2018-10-11 14:32:34 +08:00
parent d159ce46bf
commit e3e9a22181
4 changed files with 54 additions and 4 deletions
+1 -1
View File
@@ -5,6 +5,6 @@ if(WIN32)
set(SSL_LIBS ${SSL_LIBS} crypt32)
endif()
target_link_libraries(rest_github_client webcc ${Boost_LIBRARIES})
target_link_libraries(rest_github_client webcc jsoncpp ${Boost_LIBRARIES})
target_link_libraries(rest_github_client "${CMAKE_THREAD_LIBS_INIT}")
target_link_libraries(rest_github_client ${SSL_LIBS})
+26 -1
View File
@@ -1,13 +1,38 @@
#include <iostream>
#include "json/json.h"
#include "webcc/rest_ssl_client.h"
#include "webcc/logger.h"
static Json::Value StringToJson(const std::string& str) {
Json::Value json;
Json::CharReaderBuilder builder;
std::stringstream stream(str);
std::string errs;
if (!Json::parseFromStream(builder, stream, &json, &errs)) {
std::cerr << errs << std::endl;
}
return json;
}
void Test() {
webcc::RestSslClient client("api.github.com");
if (client.Get("/events")) {
std::cout << client.response()->content() << std::endl;
Json::Value json = StringToJson(client.response()->content());
// Pretty print the JSON.
Json::StreamWriterBuilder builder;
builder["indentation"] = " ";
std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
writer->write(json, &std::cout);
std::cout << std::endl;
} else {
std::cout << webcc::DescribeError(client.error());
if (client.timed_out()) {