Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
475 views
in Technique[技术] by (71.8m points)

curl - 用Curl发布(Posting with Curl)

So I have a thermostat, which has a connection through browser, but doesn't have an API, and I'd like to post with curl, so I can control it with Home Assistant.

(因此,我有一个恒温器,该恒温器可以通过浏览器进行连接,但是没有API,并且我想使用curl进行发布,因此可以使用Home Assistant对其进行控制。)

I have a working culr, which sets temperature on a designated thermostat.

(我有一个工作人员,可以在指定的恒温器上设定温度。)

COOKIE=`curl -v -X POST -F 'lang=2' -F "username=${USER}" -F "password=${PASS}" https://website/login 2>&1 | grep Set-Cookie | cut -d';' -f1 | cut -d' ' -f3`
curl -X POST -F "h=${THERM}" -F 'save=1' -F "robj[${THERM}]=${TEMP}" --cookie "${COOKIE}" https://website/ajax/thermostats >/dev/null 2>&1
;;

But I would like to post other thing on this thermostat.

(但我想在此恒温器上发布其他内容。)

curl ' https://website/ajax/thermostats ' -H 'Connection: keep-alive' -H 'Accept: / ' -H 'Origin: https://webshite ' -H 'X-Requested-With: XMLHttpRequest' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded;

(curl'https :// website / ajax / thermostats' -H'连接:keep- alive' -H'接受: / '-H'来源: https:// webshite' - H'X -Requested-With:XMLHttpRequest' -H'用户代理:Mozilla / 5.0(Macintosh; Intel Mac OS X 10_15_1)AppleWebKit / 537.36(KHTML,如Gecko)Chrome / 78.0.3904.108 Safari / 537.36'-H'内容类型:application / x-www-形式编码)

charset=UTF-8' -H 'Sec-Fetch-Site: same-origin' -H 'Sec-Fetch-Mode: cors' -H 'Referer: https://website/thermostats/1.7 ' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: hu,en-US;q=0.9,en;q=0.8' -H 'Cookie: tmygreenhouse=aaaaaaaa' --data 'h=1.7&ce=0' --compressed

(charset = UTF-8'-H'Sec-Fetch-Site:same-origin'-H'Sec-Fetch-Mode:cors'-H'Referer: https://website/thermostats/1.7'-H'Accept-编码:gzip,deflate,br'-H'接受语言:hu,en-US; q = 0.9,en; q = 0.8'-H'Cookie:tmygreenhouse = aaaaaaaa'--data'h = 1.7&ce = 0 '-压缩)

Managed to check the curl which is posted by the browser, and found out, the key is ce=0 (which is off) and ce=1 (which is on) how could I implement this into my already working curl?

(设法检查由浏览器发布的curl,并发现,关键是ce = 0(已关闭)和ce = 1(已打开)如何将其实现到我已经在工作的curl中?)

Tried to add --data 'h=1.7&ce=0', but probably it needs other paramethers :/

(试图添加--data'h = 1.7&ce = 0',但可能需要其他参数:/)

  ask by syluccy translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...