#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