繁体   English   中英

如何使用 CURLPP 库通过 C/C++ 代码检查网站是 http 还是 https?

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

在谷歌上进行了大量研究后,我能够使用 curlpp 库通过 C++ 代码发送 http 请求,并且得到如下响应:

输出:

# 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>

但我只想将https://mail.google.com/mail/部分存储在变量中。 我怎样才能做到这一点?

程序:

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

用 HTTP 调用点击它,看到响应是 2xx。 然后用 HTTPS 调用点击它,看看响应是否是 2xx。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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