Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Http Post
#1
Hi Dean, 


Quote:Sub SendPostToCQCTest()

Dim Result As String, status As String
Dim myURL As String, postData As String
Dim winHttpReq As Object
Set winHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
 
myURL = "http://10.0.1.8:45822/TOSmessage"
postData = "a=15.2"
winHttpReq.Open "POST", myURL, False
winHttpReq.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
winHttpReq.Send postData
Result = winHttpReq.responseText
status = winHttpReq.status
End Sub

This is some VBA code to post a message to CQC HTTP listener. 

I have a similar routine sent from a Raspberry Pi device that works as expected. In the case above, CQC is not receiving the postData string even though I know it's receiving the HTTP Post. I have a log set up to monitor it.

Is there something you can see that would prevent the receipt of the postData?
Reply
#2
Can you use some sort of little doohicky program that you can send that to and capture the raw data that shows up? That would make it a lot more obvious what is going on.
Dean Roddey
Software Geek Extraordinaire
Reply
#3
(08-05-2018, 08:59 AM)Dean Roddey Wrote: Can you use some sort of little doohicky program that you can send that to and capture the raw data that shows up? That would make it a lot more obvious what is going on.

MessageNumber DiagnosisTypes Timestamp TimeDelta EventRecord.Header.ProcessId EventRecord.Header.ThreadId Module Summary
7510 None 2018-08-05T11:24:29.2282435 0.0005846 3652 1676 HTTP Response, Status: OK (200), Version: HTTP/1.0
7507 None 2018-08-05T11:24:29.2276589 0.0000000 0 0 HTTP Request, POST /TOSmessage, Version: HTTP/1.1

I can provide more detail if needed.


This one was interesting:

Name Value Bit Offset Bit Length Type
Payload ${²þò.¿¹.=.\P...;à..a=15.2 160 208 BinaryValue
Reply
#4
That's not really the raw HTTP text. And yeh, it saying the value was binary is sort of wrong.
Dean Roddey
Software Geek Extraordinaire
Reply
#5
(08-05-2018, 08:59 AM)Dean Roddey Wrote: Can you use some sort of little doohicky program that you can send that to and capture the raw data that shows up? That would make it a lot more obvious what is going on.

Let me give you some more detail:

Name Value Bit Offset Bit Length Type
Method POST 0 32 String
Uri /TOSmessage 40 88 HTTP.UriType
Version HTTP/1.1 136 64 HTTP.VersionType
Headers map{Connection=[Keep-Alive],Content-Type=application/x-www-form-urlencoded;Charset=UTF-8,Accept=[*/*],User-Agent=Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5),Content-Length=6,Host=10.0.1.8:45822} 216 1720 MapValue`2
Payload a=15.2 1936 48 BinaryValue

Name Value Bit Offset Bit Length Type
Version HTTP/1.0 0 64 HTTP.VersionType
StatusCode 200 72 24 UInt32
ReasonPhrase OK 104 16 String
Headers map{Content-Type=text/html;charset=utf-8,Content-Length=32,Connection=[Close]} 136 648 MapValue`2
Payload <html><body>Done</body></html>.. 784 256 BinaryValue
Reply
#6
Dean, 

In HTML 1.0 you have to open and then close the connection for each command sent
In HTML 1.1 you can open a connection and have a persistent state 

In my other application, Raspberry Pi, I am sending a command to close the connection, but VBA is HTML 1.1 and it doesnt even offer a command to close the connection. It get performed with the post method, I guess. 

I don't know if that's causing the problem, but its something I thought of.
Reply
#7
The program you run I assume just runs and exits, right? So it will close the connection when it exits and the server will see that. You can always include a Close header line to make it clearer to the server that it's a one shot operation.

Actually I just realized you said the listener driver, not the web server. I don't think that the listener driver is going to do anything with post parameters encoded in the body. It only deals with query parameters. So re-do it as a GET and do the values you are passing as query parms, so

?a=15.2

and so forth. See if that doesn't work.
Dean Roddey
Software Geek Extraordinaire
Reply
#8

Message Offset: 0
0C 00 00 00 0C 00 00 00 36 00 00 00 B8 E8 56 2B
 .  .  .  .  .  .  .  .  6  .  .  .  ¸  è  V  +
1A F6 00 0C 29 6A CB A5 08 00 45 00 00 AA 04 F8
 .  ö  .  .  )  j  Ë  ¥  .  .  E  .  .  ª  .  ø
40 00 80 06 00 00 0A 00 01 08 0A 00 01 66 B2 FE
 @  .  .  .  .  .  .  .  .  .  .  .  .  f  ²  þ
24 7B 8D 3D 85 5C F2 06 BF BF 50 18 01 00 17 0A
 $  {  .  =  .  \  ò  .  ¿  ¿  P  .  .  .  .  .
00 00
 .  .
0C 00 00 00 0C 00 00 00 82 00 00 00 48 54 54 50
 .  .  .  .  .  .  .  .  .  .  .  .  H  T  T  P
2F 31 2E 30 20 32 30 30 20 4F 4B 0D 0A 43 6F 6E
 /  1  .  0     2  0  0     O  K  .  .  C  o  n
74 65 6E 74 2D 54 79 70 65 3A 20 74 65 78 74 2F
 t  e  n  t  -  T  y  p  e  :     t  e  x  t  /
68 74 6D 6C 3B 20 63 68 61 72 73 65 74 3D 75 74
 h  t  m  l  ;     c  h  a  r  s  e  t  =  u  t
66 2D 38 0D 0A 43 6F 6E 74 65 6E 74 2D 4C 65 6E
 f  -  8  .  .  C  o  n  t  e  n  t  -  L  e  n
67 74 68 3A 20 33 32 0D 0A 43 6F 6E 6E 65 63 74
 g  t  h  :     3  2  .  .  C  o  n  n  e  c  t
69 6F 6E 3A 20 43 6C 6F 73 65 0D 0A 0D 0A 3C 68
 i  o  n  :     C  l  o  s  e  .  .  .  .  <  h
74 6D 6C 3E 3C 62 6F 64 79 3E 44 6F 6E 65 3C 2F
 t  m  l  >  <  b  o  d  y  >  D  o  n  e  <  /
62 6F 64 79 3E 3C 2F 68 74 6D 6C 3E 0D 0A
 b  o  d  y  >  <  /  h  t  m  l  >  .  .

Message Offset: 0
0C 00 00 00 0C 00 00 00 2C 01 00 00 00 0C 29 6A
 .  .  .  .  .  .  .  .  ,  .  .  .  .  .  )  j
CB A5 B8 E8 56 2B 1A F6 08 00 45 00 01 1A 4A FE
 Ë  ¥  ¸  è  V  +  .  ö  .  .  E  .  .  .  J  þ
40 00 80 06 98 72 0A 00 01 66 0A 00 01 08 24 7B
 @  .  .  .  .  r  .  .  .  f  .  .  .  .  $  {
B2 FE F2 06 BE C7 8D 3D 85 5C 50 18 01 00 8F 1D
 ²  þ  ò  .  ¾  Ç  .  =  .  \  P  .  .  .  .  .
00 00 50 4F 53 54 20 2F 54 4F 53 6D 65 73 73 61
 .  .  P  O  S  T     /  T  O  S  m  e  s  s  a
67 65 20 48 54 54 50 2F 31 2E 31 0D 0A 43 6F 6E
 g  e     H  T  T  P  /  1  .  1  .  .  C  o  n
6E 65 63 74 69 6F 6E 3A 20 4B 65 65 70 2D 41 6C
 n  e  c  t  i  o  n  :     K  e  e  p  -  A  l
69 76 65 0D 0A 43 6F 6E 74 65 6E 74 2D 54 79 70
 i  v  e  .  .  C  o  n  t  e  n  t  -  T  y  p
65 3A 20 61 70 70 6C 69 63 61 74 69 6F 6E 2F 78
 e  :     a  p  p  l  i  c  a  t  i  o  n  /  x
2D 77 77 77 2D 66 6F 72 6D 2D 75 72 6C 65 6E 63
 -  w  w  w  -  f  o  r  m  -  u  r  l  e  n  c
6F 64 65 64 3B 20 43 68 61 72 73 65 74 3D 55 54
 o  d  e  d  ;     C  h  a  r  s  e  t  =  U  T
46 2D 38 0D 0A 41 63 63 65 70 74 3A 20 2A 2F 2A
 F  -  8  .  .  A  c  c  e  p  t  :     *  /  *
0D 0A 55 73 65 72 2D 41 67 65 6E 74 3A 20 4D 6F
 .  .  U  s  e  r  -  A  g  e  n  t  :     M  o
7A 69 6C 6C 61 2F 34 2E 30 20 28 63 6F 6D 70 61
 z  i  l  l  a  /  4  .  0     (  c  o  m  p  a
74 69 62 6C 65 3B 20 57 69 6E 33 32 3B 20 57 69
 t  i  b  l  e  ;     W  i  n  3  2  ;     W  i
6E 48 74 74 70 2E 57 69 6E 48 74 74 70 52 65 71
 n  H  t  t  p  .  W  i  n  H  t  t  p  R  e  q
75 65 73 74 2E 35 29 0D 0A 43 6F 6E 74 65 6E 74
 u  e  s  t  .  5  )  .  .  C  o  n  t  e  n  t
2D 4C 65 6E 67 74 68 3A 20 36 0D 0A 48 6F 73 74
 -  L  e  n  g  t  h  :     6  .  .  H  o  s  t
3A 20 31 30 2E 30 2E 31 2E 38 3A 34 35 38 32 32
 :     1  0  .  0  .  1  .  8  :  4  5  8  2  2
0D 0A 0D 0A 00 00 00 00
 .  .  .  .  .  .  .  .
0C 00 00 00 0C 00 00 00 40 00 00 00 00 0C 29 6A
 .  .  .  .  .  .  .  .  @  .  .  .  .  .  )  j
CB A5 B8 E8 56 2B 1A F6 08 00 45 00 00 2E 4A FF
 Ë  ¥  ¸  è  V  +  .  ö  .  .  E  .  .  .  J  ÿ
40 00 80 06 99 5D 0A 00 01 66 0A 00 01 08 24 7B
 @  .  .  .  .  ]  .  .  .  f  .  .  .  .  $  {
B2 FE F2 06 BF B9 8D 3D 85 5C 50 18 01 00 3B E0
 ²  þ  ò  .  ¿  ¹  .  =  .  \  P  .  .  .  ;  à
00 00 61 3D 31 35 2E 32 00 00 00 00
 .  .  a  =  1  5  .  2  .  .  .  .
Reply
#9
(08-05-2018, 11:19 AM)Dean Roddey Wrote: The program you run I assume just runs and exits, right? So it will close the connection when it exits and the server will see that. You can always include a Close header line to make it clearer to the server that it's a one shot operation.

Actually I just realized you said the listener driver, not the web server.  I don't think that the listener driver is going to do anything with post parameters encoded in the body. It only deals with query parameters. So re-do it as a GET and do the values you are passing as query parms, so

?a=15.2

and so forth. See if that doesn't work.

Will Do. I posted the HEX/ASCII data below. It does look like there is some garbage just prior to the data being sent. Not sure if that's the issue or not. 

Ill try the GET.
Reply
#10
I could actually pretty easily make a little HTTP capture program to help with such things. I'll put that on the list. It shouldn't be more than a casual afternoon project I think (famous last words.)
Dean Roddey
Software Geek Extraordinaire
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  HTTP Get driver not working znelbok 10 1,081 08-28-2018, 10:10 AM
Last Post: Dean Roddey
  HTTP Post zra 7 761 05-18-2018, 08:47 AM
Last Post: zra
  IFTT and HTTP Trigger parameter passing setup Shaky 5 1,601 03-09-2018, 10:20 PM
Last Post: Dean Roddey
  SSL certificate for HTTP trigger driver RichardU 7 1,385 01-16-2018, 09:50 AM
Last Post: Dean Roddey
  Zwave via http put kfly 6 2,160 11-07-2017, 07:57 AM
Last Post: kfly
  Additional HTTP REST commands requested greymatter 3 1,434 08-25-2017, 09:17 AM
Last Post: Dean Roddey
  SOLVED -- RTSP --> HTTP (NVR on iOS Devices) agarden 5 2,510 05-30-2017, 08:32 PM
Last Post: agarden
  HTTP POST? dlmorgan999 17 4,588 04-13-2017, 05:46 AM
Last Post: dlmorgan999
  HTTP-based Trigger Driver Docs znelbok 5 2,378 03-11-2017, 09:34 PM
Last Post: Dean Roddey
  download a file via http with CML? bbrendon 4 2,032 02-28-2017, 09:16 PM
Last Post: dlmorgan999

Forum Jump:


Users browsing this thread: 1 Guest(s)