• c++ poco库https调用


    #include "PocoFile.h"
    #include "PocoFileStream.h"
    #include "PocoProcess.h"
    #include "PocoRegularExpression.h"
    #include "PocoDateTime.h"
    #include "PocoDateTimeFormatter.h"
    #include "PocoDateTimeParser.h"
    #include "PocoNetHTTPSClientSession.h"
    #include "PocoNetHTTPRequest.h"
    #include "PocoNetHTTPResponse.h"
    #include "PocoNetInvalidCertificateHandler.h"
    #include "PocoNetAcceptCertificateHandler.h"
    #include "PocoURI.h"
    #include "PocoNetSSLManager.h"
    #include "PocoJSONObject.h"
    #include "PocoJSONParser.h"
    #include "PocoString.h"
    #include "PocoNetKeyConsoleHandler.h"
    #include "PocoNetConsoleCertificateHandler.h"
    #include "PocoSharedPtr.h"

    using namespace std;
    using namespace Poco;
    using namespace Poco::Net;

    try
         {
    
             transform(mac.begin(), mac.end(), mac.begin(), ::toupper);
            
             string postString = "p1=" + p1 + "&p2=" + p2 ;//这里即为传递的参数,可以用工具抓包分析,也可以自己分析,主要是form里面每一个name都要加进来  
             SSLInitializer sslInitializer;
    
             SharedPtr<InvalidCertificateHandler> ptrCert = new ConsoleCertificateHandler(false);
             Context::Ptr ptrContext = new Context(Context::CLIENT_USE, "", "", "", Context::VERIFY_NONE, 9, true, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
             SSLManager::instance().initializeClient(0, ptrCert, ptrContext);
             string url = "https://www.xxx.com/";
             URI uri(url);
             HTTPSClientSession client(uri.getHost(), uri.getPort());
             HTTPRequest request(HTTPRequest::HTTP_POST, uri.getPath());
             request.setContentType("application/x-www-form-urlencoded;charset=UTF-8");
             std::string reqBody(postString);
             request.setContentLength(reqBody.length());
    
             request.set("headerkey",postString);// 
              request.set("USER-AGENT", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36"); 
              client.sendRequest(request) << reqBody;//发送HTTP请求到指定的服务器 
              HTTPResponse response; 
              istream& is = client.receiveResponse(response);//声明一个引用,接收HTTP请求响应 // 
              if (response.getStatus() == Poco::Net::HTTPResponse::HTTP_OK) 
              { 
                log("response HTTP_OK contentLength" + std::to_string(response.getContentLength())); 
                char* pData = new char[response.getContentLength()]; 
                is.read(pData, response.getContentLength()); 
                std::string srcString(pData, response.getContentLength()); 
                log("httppost-result2=" + srcString); 
                return DeserializeResponse(srcString); 
              } 
              catch (Poco::Exception ex) 
              { 
                log( " Message=" + ex.message()); /* 
              }

    from:http://stackoverflow.com/questions/10875938/how-to-use-openssl-in-poco-c-library-correctly

  • 相关阅读:
    java分页查询--oracle
    Tomcat Excel中的数据导出到页面中显示
    接口调用类3
    接口工具类2
    接口工具类
    redis 对外访问
    Spring 项目启动时执行
    scp 本地上传/下载服务器文件
    CentOS 安装 rabbitMQ
    卸载rabbitMQ
  • 原文地址:https://www.cnblogs.com/xuan52rock/p/6053651.html
Copyright © 2020-2023  润新知