简体   繁体   中英

How to check whether a website is http or https, via C/C++ code using CURLPP library?

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 ;
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM