Closed COM8 closed 1 year ago
I get an error when I compile the example with cmake.
error: ‘class cpr::MultiPerform’ has no member named ‘front’
28 | std::cout << "Request url: " << multi.front().GetFullRequestUrl() << '\n';
| ^~~~~1
This is how I included this PR.
FetchContent_Declare(
cpr
GIT_REPOSITORY https://github.com/libcpr/cpr.git
GIT_TAG 155f3f44bb9add8a7e96a7b89e31c02771eb43a5
)
Fixed the example code. It should be multi.GetSessions().front().first->GetFullRequestUrl();
.
If more than one session is added to the multiPerform, only the first session gets printed out.
int main() {
std::shared_ptr<cpr::Session> session_1 = std::make_shared<cpr::Session>();
std::shared_ptr<cpr::Session> session_2 = std::make_shared<cpr::Session>();
session_1->SetUrl("https://duckduckgo.com");
session_2->SetUrl("https://google.com");
cpr::MultiPerform multiPerform;
multiPerform.AddInterceptor(std::make_shared<LoggingInterceptor>());
multiPerform.AddSession(session_1);
multiPerform.AddSession(session_2);
std::vector<cpr::Response> responses = multiPerform.Get();
}
Output.
Request url: https://duckduckgo.com
Response status code: 200
This is expected since you print here only the first one:
std::cout << "Request url: " << multi.GetSessions().front().first->GetFullRequestUrl(); << '\n';
You can iterate over multi.GetSessions()
to print all.
You can iterate over multi.GetSessions() to print all.
You should put that in the documentation.
Awesome! Then I will merge this PR as soon as I have time to update the docs accordingly.
Docs are available here: https://github.com/libcpr/docs/pull/34
This PR adds support for intercepts when using
cpr::MultiPerform
. Fixes #862.Examples: