zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    如何利用京东云的对象存储(OSS)上传下载文件
    2017年4月8日Office 365 使用CSV文件导入邮件组
    在Office 365 的如何给管理员赋予查看所有人邮箱的权限的Powershell
    Office 365 Powershell 连接命令
    Office365创建通讯组
    国际版删除域名的步骤
    如何停止AAD服务
    导出Office365中的组及成员
    AWS/阿里/Azure,云厂商价格大PK
    OA系统与Exchange 日历打通
  • 原文地址:https://www.cnblogs.com/xuan52rock/p/6053651.html
Copyright © 2011-2022 走看看