News:

  • July 25, 2026, 09:10:09 AM

Login with username, password and session length

Author Topic: HTTPCMD problems  (Read 15509 times)

Bolt

  • Hero Member
  • *****
  • Posts: 598
HTTPCMD problems
« on: October 18, 2020, 04:58:46 PM »
I am trying to implement a POST via HTTPCMD.  I can accomplish it successfully via Postman.  I'm struggling with how to copy the API info from Postman to DmD.

This works simply in Postman, and returns UID and Token values.  Here it results in a 404 error.

What am I missing here?  I have also tried Additional User Request Header "Content-Type:application/json". I have also added this to Request "Content-Type:" at the bottom.


My Server is https, when I select Use SSL / TLS and TCP Port 443 I get an ERR:
Code: [Select]
SSL/TLS handhsake failed. in HTTPCMD @0000007D (yes, there really is a typo there).
« Last Edit: October 18, 2020, 05:06:50 PM by Bolt »

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6168
  • Yes Pinky, Do-more will control the world!
Re: HTTPCMD problems
« Reply #1 on: October 19, 2020, 02:41:21 PM »
Something in the TLS/SSL handshake is failing. The rest of the request is irrelevant after the handshake failed.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: HTTPCMD problems
« Reply #2 on: October 19, 2020, 03:14:52 PM »
But I get a 404 error when not at SSL / TLS.  It is a https URL, should I run it as SSL?

Here's my DMLogger when running on port 80.

Code: [Select]
192.168.17.18  Port 29298(0x7272),10/19/20 14:12:18.418 ,"<!DOCTYPE html>.<html lang=en>.  <meta charset=utf-8>.  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">.  <title>Error 404 (Not Found)!!1</title>.  <style>.    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-ser"

192.168.17.18  Port 29298(0x7272),10/19/20 14:12:18.417 ,"HTTP disconnected!"

192.168.17.18  Port 29298(0x7272),10/19/20 14:12:18.416 ,"Disconnecting HTTP..."

192.168.17.18  Port 29298(0x7272),10/19/20 14:12:18.415 ,"Connection: close"

192.168.17.18  Port 29298(0x7272),10/19/20 14:12:18.415 ,"Date: Mon, 19 Oct 2020 19:12:19 GMT"

192.168.17.18  Port 29298(0x7272),10/19/20 14:12:18.414 ,"Content-Length: 1566"

192.168.17.18  Port 29298(0x7272),10/19/20 14:12:18.413 ,"Referrer-Policy: no-referrer"

192.168.17.18  Port 29298(0x7272),10/19/20 14:12:18.413 ,"Content-Type: text/html; charset=UTF-8"

192.168.17.18  Port 29298(0x7272),10/19/20 14:12:18.339 ,"Content-Type: application/json.."

192.168.17.18  Port 29298(0x7272),10/19/20 14:12:18.339 ,"Content-Length: 65.."

192.168.17.18  Port 29298(0x7272),10/19/20 14:12:18.338 ,"Accept-Encoding: identity.."

192.168.17.18  Port 29298(0x7272),10/19/20 14:12:18.337 ,"Host: us-central#####.#######ons.netP.."

192.168.17.18  Port 29298(0x7272),10/19/20 14:12:18.337 ,"POST t#####/login HTTP/1.1.."

192.168.17.18  Port 29298(0x7272),10/19/20 14:12:18.336 ,"HTTP connected!"

192.168.17.18  Port 29298(0x7272),10/19/20 14:12:18.336 ,"Connecting to HTTP server..."

192.168.17.18  Port 29298(0x7272),10/19/20 14:12:18.335 ,"DNS lookup complete"

192.168.17.18  Port 29298(0x7272),10/19/20 14:12:18.257 ,"Beginning DNS lookup..."

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6168
  • Yes Pinky, Do-more will control the world!
Re: HTTPCMD problems
« Reply #3 on: October 19, 2020, 03:33:33 PM »
No, sorry. I got drawn to the later error.

Apparently the request isn't getting formed quite right. I would probably Wireshark and look at the on-the-wire difference between Postman and the PLC, and then go from there.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: HTTPCMD problems
« Reply #4 on: October 20, 2020, 01:12:15 AM »
I'm afraid I don't know enough of what I'm looking at in WireShark.  The one thing that does keep coming back to me is the extra 'P' added after the URL, before the <CR><LF> in DmLogger, but that may be a logging syntax problem only?

So I have simplified even further, using a dummy API.  It is simply POST http://dummy.restapiexample.com/api/v1/create, which in Postman works without any body, etc.

Here's my DmLogger result when run in DmSim:
Code: [Select]
192.168.17.18  Port 29298(0x7272),10/20/20 00:04:02.096 ,"TCP connection failed or was unexpectedly closed in HTTPCMD @000000F3"

192.168.17.18  Port 29298(0x7272),10/20/20 00:04:02.096 ,"HTTP disconnected!"

192.168.17.18  Port 29298(0x7272),10/20/20 00:04:02.095 ,"Disconnecting HTTP..."

192.168.17.18  Port 29298(0x7272),10/20/20 00:04:02.095 ,"Server connection closed."

192.168.17.18  Port 29298(0x7272),10/20/20 00:04:01.939 ,"Accept-Encoding: identity.."

192.168.17.18  Port 29298(0x7272),10/20/20 00:04:01.939 ,"Host: dummy.restapiexample.comP.."

192.168.17.18  Port 29298(0x7272),10/20/20 00:04:01.939 ,"POST api/v1/create HTTP/1.1.."

192.168.17.18  Port 29298(0x7272),10/20/20 00:04:01.939 ,"HTTP connected!"

192.168.17.18  Port 29298(0x7272),10/20/20 00:04:01.861 ,"Connecting to HTTP server..."

192.168.17.18  Port 29298(0x7272),10/20/20 00:04:01.861 ,"DNS lookup complete"

192.168.17.18  Port 29298(0x7272),10/20/20 00:04:01.860 ,"Beginning DNS lookup..."

Does anyone have a sample program with a working HTTPCMD API?

I am running DmD 2.7.4.
« Last Edit: October 20, 2020, 01:15:32 AM by Bolt »

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6168
  • Yes Pinky, Do-more will control the world!
Re: HTTPCMD problems
« Reply #5 on: October 20, 2020, 01:27:22 PM »
I can duplicate it. The "Host: ..." logging issue was mostly cosmetic. It's fixed.

The only thing I see different is that BRX is sending the request in multiple packets, which should be valid. BRX shouldn't actually be doing that, so I don't know what's going on there, but I am going to force the request into a single packet and see if it gets happy. Once it is, I'll dig into to why the stream is getting chopped up.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: HTTPCMD problems
« Reply #6 on: October 20, 2020, 01:42:19 PM »
Do you mean the Simulator is chopping it up into multiple packets?

Should I try this on a BRX instead of Sim?

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6168
  • Yes Pinky, Do-more will control the world!
Re: HTTPCMD problems
« Reply #7 on: October 20, 2020, 01:54:20 PM »
Do you mean the Simulator is chopping it up into multiple packets?

Should I try this on a BRX instead of Sim?

No. BRX was chopping it. That should be completely legal.

Change your HTTP request from "api/v1/create" to "/api/v1/create".
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: HTTPCMD problems
« Reply #8 on: October 20, 2020, 02:11:25 PM »
adding the "extra" / in the request returns 403 Forbidden.

Code: [Select]
192.168.17.18  Port 29298(0x7272),10/20/20 13:10:08.129 ,"Forbidden"

192.168.17.18  Port 29298(0x7272),10/20/20 13:10:08.129 ,"HTTP disconnected!"

192.168.17.18  Port 29298(0x7272),10/20/20 13:10:08.128 ,"Disconnecting HTTP..."

192.168.17.18  Port 29298(0x7272),10/20/20 13:10:08.127 ,"Content-Length: 9"

192.168.17.18  Port 29298(0x7272),10/20/20 13:10:08.127 ,"Date: Tue, 20 Oct 2020 18:10:08 GMT"

192.168.17.18  Port 29298(0x7272),10/20/20 13:10:08.126 ,"Content-Type: text/plain"

192.168.17.18  Port 29298(0x7272),10/20/20 13:10:07.815 ,"Accept-Encoding: identity.."

192.168.17.18  Port 29298(0x7272),10/20/20 13:10:07.815 ,"Host: dummy.restapiexample.comP.."

192.168.17.18  Port 29298(0x7272),10/20/20 13:10:07.814 ,"POST /api/v1/create HTTP/1.1.."

192.168.17.18  Port 29298(0x7272),10/20/20 13:10:07.814 ,"HTTP connected!"

192.168.17.18  Port 29298(0x7272),10/20/20 13:10:07.737 ,"Connecting to HTTP server..."

192.168.17.18  Port 29298(0x7272),10/20/20 13:10:07.736 ,"DNS lookup complete"

192.168.17.18  Port 29298(0x7272),10/20/20 13:10:07.736 ,"Beginning DNS lookup..."

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6168
  • Yes Pinky, Do-more will control the world!
Re: HTTPCMD problems
« Reply #9 on: October 20, 2020, 02:17:13 PM »
You have a body in that request. Is that causing issues? It's answering as expected for me.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: HTTPCMD problems
« Reply #10 on: October 20, 2020, 02:27:19 PM »
I'm not following, there's not a request body?

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6168
  • Yes Pinky, Do-more will control the world!
Re: HTTPCMD problems
« Reply #11 on: October 20, 2020, 02:58:28 PM »
I'm not following, there's not a request body?

I saw the content length in the dump and thought it was request body length. I've got about 5 things going right now. ;)

Not sure what the difference is. This is what I'm getting.

"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: HTTPCMD problems
« Reply #12 on: October 20, 2020, 10:51:49 PM »
I don't understand.  I can create a new project, add HTTPCMD in $Main, send to Sim, run it, no luck.  403 Forbidden.

On that note, how do I fully clear the Sim's memory, etc?  Everytime I open it, the SS and V values show values I put in there 2 months ago.  Something is retaining the memory.

Does anyone have a working API program they would like to share?

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: HTTPCMD problems
« Reply #13 on: October 20, 2020, 11:02:32 PM »
I just logged into a BRX, different internet, etc, added the rungs to $Main, same result, 403 Forbidden.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6168
  • Yes Pinky, Do-more will control the world!
Re: HTTPCMD problems
« Reply #14 on: October 21, 2020, 11:34:56 AM »
Tested on the Sim. Worked same as BRX.

I wish I knew what to suggest. I trimmed the Postman request back to exactly match BRX, but they both worked. I have never seen the 403 response.

To answer your question, you can clear the sim with the PLC->Clear PLC Memory option, or you can delete the files that it stores it's state in. The files are stored in "C:\Users\Public\Public Documents\Do-more\Designer2_X\Bin". The files are DmSim.DAT and DmSim.STATE.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO