POCO C++ - NET SSL - how to POST HTTPS request
You are setting content type like this:
req.setContentType("Content-Type: application/x-www-form-urlencoded\r\n");
which should be:
req.setContentType("application/x-www-form-urlencoded\r\n");
HTTPS request in c++ using Poco
I found the answer. I wasn't really getting the certificate. It works like this:
try{
Poco::Net::initializeSSL();
Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> ptrHandler = new AcceptCertificateHandler(false);
Context::Ptr ptrContext = new Context(Context::CLIENT_USE, "", "", "", Context::VERIFY_RELAXED, 9, true, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
SSLManager::instance().initializeClient(0, ptrHandler, ptrContext);
Poco::Net::SocketAddress address("www.server.com:443");
Poco::Net::SecureStreamSocket socket(address);
if (socket.havePeerCertificate())
{
X509Certificate cert = socket.peerCertificate();
std::cout<<cert.issuerName()<<"\n";
}
else
{
std::cout<<"No certificate";
}
}catch (Poco::Exception& e) {
std::cout << "Error: " << e.displayText() << "\n";
return -1;
}
Upload a file using POCO - SSL Connection Unexpectedly Closed Exception
I am able to handle the exception by reading the response body character by character. Here is the complete code to upload a file using POCO.
http://developersarea.wordpress.com/2014/10/08/upload-files-using-poco-c-libraries/
Related Topics
Getting the Current Time (In Milliseconds) from the System Clock in Windows
How to Define a Move Constructor
How to Find the Qt5 Cmake Module on Windows
Command Line Compile Using Cl.Exe
C++11 Compiler: Closest to the Standard and How Close
C++ Object Instantiation VS Assignment
Using Continue in a Switch Statement
How to Perform a Pairwise Binary Operation Between the Elements of Two Containers
C++ Remove_If on a Vector of Objects
Does Std::Array<> Guarantee Allocation on the Stack Only
Which MACro to Wrap MAC Os X Specific Code in C/C++
How to Detect Possible/Potential Stack Overflow Problems in a C/C++ Program