Search code examples
posthttpschilkat

Chilkat HTTPS The plain HTTP request was sent to HTTPS port


I m using Chilkat ActiveX (Delphi) version 9.5. I use TChilkatHTTP to POST some data to a HTTPS url.

http.SynchronousRequest(Host,443,0,req.ControlInterface);

The response I got is "The plain HTTP request was sent to HTTPS port"

I have googled many days for a solution but unable to find a working solution. Pls if anyone know what have I missed.

Thanks a lot.

Below is the Chilkat log:

---- Sending ----
POST /qrCreate HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: api-testing.payhalal.my
Content-Length: 232

app_id=app-testing-d2277670007a30c2e6b6919fdfc696dd&amount=&currency=MYR&product_description=MY%20PRODUCT&order_id=12345&customer_name=SHELY&customer_email=eeshely%40gmail.com&customer_phone=0127806698&language=EN&timeout=3600&hash=
---- Received ----
HTTP/1.1 400 Bad Request
Server: nginx
Date: Thu, 12 Sep 2019 10:23:07 GMT
Content-Type: text/html
Content-Length: 264
Connection: close
Strict-Transport-Security: max-age=31536000; includeSubDomains

<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx</center>
</body>
</html>
<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx</center>
</body>
</html>

Solution

  • Change

    http.SynchronousRequest(Host,443,0,req.ControlInterface); 
    

    to this:

    http.SynchronousRequest(Host,443,1,req.ControlInterface); 
    

    The 3 argument indicates whether TLS should be used. The 2nd arg is just the port number.