![](/img/trans.png)
[英]C++ - how to send a HTTP post request using Curlpp or libcurl
[英]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.