-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhttpResponseBody.cpp
44 lines (38 loc) · 1.22 KB
/
httpResponseBody.cpp
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <Poco/Net/HTTPClientSession.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPResponse.h>
#include <Poco/Net/HTTPMessage.h>
#include <Poco/URI.h>
using namespace std;
using namespace Poco;
using namespace Poco::Net;
int main()
{
// Create a URI
URI uri("http://httpbin.org");
// Create a session
HTTPClientSession session(uri.getHost(), uri.getPort());
// Set connection to keepalive
session.setKeepAlive(true);
// Choose the http request method
HTTPRequest request(HTTPRequest::HTTP_GET, "/", HTTPMessage::HTTP_1_1);
// Add headers
request.add("User-Agent", "Mozilla/5.0");
// Send the request
session.sendRequest(request);
// Receive response
HTTPResponse response;
istream &page = session.receiveResponse(response);
// Store received body
string received = ""; // Store the body in string
string tmp; // Temporary variable
while(getline(page,tmp)) // Loop into each line of page
{
received += tmp + "\n"; // Insert each line into variable received with endline
}
// Print the stored body
cout << received << endl;
// Now compile the code and open wireshark
return 0;
}