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

标签 c++ c http curlpp

在谷歌上进行了大量研究后,我能够使用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。

关于c++ - 如何使用 CURLPP 库通过 C/C++ 代码检查网站是 http 还是 https?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25236495/

相关文章:

Android:检查网络和真实的互联网连接

c# - 使用C#在html文档中抓取JavaScript动态生成的数据

c++ - 程序输出 "Heads"而不管随机生成的答案

C++ 读取 char* 中的注册表字符串值

c++ - 如何在不使用类次的情况下找到 TMax

c - 意外输出 printf 语句

c - "multiple definition of"编译错误的链接问题

从内联汇编 VS2012 调用 C 函数 - 段错误?

JQuery 停留在 CORS 预检和 IIS 幽灵响应

javascript - QT5 - QDataStream - 使用 javascript 序列化和反序列化