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