-5

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 ;
}
DragonX
  • 371
  • 2
  • 6
  • 18
  • Now its narrowed down, please unblock it... – DragonX Aug 11 '14 at 13:53
  • There should be a `Location` header, eg. `Location: https://mail.google.com/mail/`. – Martin Tournoij Aug 11 '14 at 14:29
  • @Carpetsmoker yes you are right. I am trying to find the same but couldn't. The `myRequest.perform( )` directly prints out the response on the terminal. I searched whole curlpp lib for `Location`, but no idea how its getting accessed – DragonX Aug 12 '14 at 11:14

1 Answers1

0

Hit it with an HTTP call and see the response is 2xx. Then hit it with an HTTPS call and see if the response is 2xx.

amortaza
  • 364
  • 1
  • 14
  • +1 That's basically what it comes down to... make a TCP connection, send it `GET /\r\r`, read a bit back and see if it's got a ` ` tag... – Tony Delroy Aug 11 '14 at 06:48