-5

在谷歌上进行了大量研究后,我可以使用 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 ;
}
4

1 回答 1

0

使用 HTTP 调用点击它,然后查看响应为 2xx。然后用 HTTPS 调用来访问它,看看响应是否为 2xx。

于 2014-08-11T05:48:12.993 回答