Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HTTP Post
#1
Dean, I was wondering if you or anyone else can help me with this:

##########################################################################################
# FUNCTION sendpost
# INPUT - outpost or inpost
# SENDS AN HTML POST TO CQC MASTER SERVER
# RETURNS - NOTHING
##########################################################################################
#
def sendpost(tosend,param):
        httpServ = httplib.HTTPConnection("10.0.1.8", 17942)
        httpServ.connect()

        if tosend == "outpost":
                httpServ.request('POST', '/VanOutRange?1=%s' % param)
                response = httpServ.getresponse()

        elif tosend == "inpost":
                httpServ.request('POST', '/VanInRange?1=%s' % param)
                response = httpServ.getresponse()

        httpServ.close()
# FUNCTION sendpost END
##########################################################################################

This is python code which sends a post to the CQC Html listener with one parameter. 

The parameter is read by the listener as CQCActParm_2. 

Works fine, but I'd like to send more than one parameter. I can't get the python code to work nor can I find any good examples on the net. 

I've tried various forms of: 

httpServ.request('POST', '/VanOutRange?1=%s' % param)

httpServ.request('POST', '/VanOutRange?1=%s2=%s2' % param % param2)

The latter fails with an error. 

Any idea what the right format might be?
Reply
#2
Keep in mind that the HTTP URL requires an ampersand between the parameters. So, assuming the last one above is correct, you would want to add an ampersand before the first 2.

httpServ.request('POST', '/VanOutRange?1=%s&2=%s2' % param % param2)

Of course ampersand may be a special character in Python, so you might have to escape it to get to be taken literally.
Dean Roddey
Software Geek Extraordinaire
Reply
#3
(05-17-2018, 09:35 AM)Dean Roddey Wrote: Keep in mind that the HTTP URL requires an ampersand between the parameters. So, assuming the last one above is correct, you would want to add an ampersand before the first 2.

httpServ.request('POST', '/VanOutRange?1=%s&2=%s2' % param % param2)

Of course ampersand may be a special character in Python, so you might have to escape it to get to be taken literally.

 httpServ.request('POST', '/TempListener1?1=%s&2=%s' % param1&param2)

I tried this and it gives an error. 

Anything else you can see in there that I might try?
Reply
#4
BTW, that's a different program than the original code I sent you, but same idea.
Reply
#5
I know nothing about Python. Is there any way you can see the resulting text that youa re creating? I'm guessing that you don't want the ampersand in the right hand side. That's Python syntax over there. You need it on the left side because that's HTML syntax.
Dean Roddey
Software Geek Extraordinaire
Reply
#6
(05-17-2018, 09:59 AM)Dean Roddey Wrote: I know nothing about Python. Is there any way you can see the resulting text that youa re creating? I'm guessing that you don't want the ampersand in the right hand side. That's Python syntax over there. You need it on the left side because that's HTML syntax.

Thanks Dean. 

I can't figure it out. I think that's an outdated way of sending HTML posts and so there aren't any examples. 

It's not a big deal.
Reply
#7
Maybe try GET instead of post. I'm don't know Python either but I've seen this work better elsewhere.
My Other web server is Dropbox.
Reply
#8
(05-18-2018, 06:14 AM)RichardU Wrote: Maybe try GET instead of post. I'm don't know Python either but I've seen this work better elsewhere.

Thanks Richard. 

Ill look into that.
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Http Post zra 17 196 08-05-2018, 01:55 PM
Last Post: zra
  IFTT and HTTP Trigger parameter passing setup Shaky 5 654 03-09-2018, 10:20 PM
Last Post: Dean Roddey
  SSL certificate for HTTP trigger driver RichardU 7 806 01-16-2018, 09:50 AM
Last Post: Dean Roddey
  Zwave via http put kfly 6 1,482 11-07-2017, 07:57 AM
Last Post: kfly
  Additional HTTP REST commands requested greymatter 3 986 08-25-2017, 09:17 AM
Last Post: Dean Roddey
  SOLVED -- RTSP --> HTTP (NVR on iOS Devices) agarden 5 1,887 05-30-2017, 08:32 PM
Last Post: agarden
  HTTP POST? dlmorgan999 17 3,430 04-13-2017, 05:46 AM
Last Post: dlmorgan999
  HTTP-based Trigger Driver Docs znelbok 5 1,854 03-11-2017, 09:34 PM
Last Post: Dean Roddey
  download a file via http with CML? bbrendon 4 1,720 02-28-2017, 09:16 PM
Last Post: dlmorgan999
  HTTP login required for driver znelbok 6 1,862 10-10-2016, 02:20 PM
Last Post: znelbok

Forum Jump:


Users browsing this thread: 1 Guest(s)