After researching a lot on google, I am able to send http request via c++ code using curlpp library and I am getting response as below:
output:
# g++ -o Curlpp Curlpp.C -lcurlpp
#./Curlpp
inside try:
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://mail.google.com/mail/">here</A>.
</BODY></HTML>
But I want to store only https://mail.google.com/mail/
part in a variable. How can I do that?
program:
#include <iostream>
#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
using namespace cURLpp ; // notice the uppercase
using namespace Options ; // notice the uppercase
using namespace std ;
int main( int , char ** )
{
try
{
cout << "inside try: " << endl;
/* Our request to be sent */
Easy myRequest ;
/* Set the options */
myRequest.setOpt( Url( "gmail.com" ) ) ;
/* Perform request */
myRequest.perform( ) ;
}
catch ( RuntimeError & e )
{
cout << "inside RuntimeError & e: " << endl;
cout << e.what( ) << endl ;
}
catch ( LogicError & e )
{
cout << "inside LogicError & e: " << endl;
cout << e.what( ) << endl ;
}
return 0 ;
}