如何使用Linux的卷曲登录从其获取一次数据记录? [英] How to use linux curl to login and retreive data once logged?

查看:162
本文介绍了如何使用Linux的卷曲登录从其获取一次数据记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个设备斯宝亚创热泵回家,我想用 Linux的shell卷曲(不PHP)卷曲登陆(POST)和获取(GET)数据登录后

I have a device Stiebel Eltron heat pump home and I would like to use Linux shell curl (not php) curl to login (POST) and retrieve (GET) data once logged

下面是我的卷曲登录POST调用的样子(我用萤火虫+的坚持的选项复制/粘贴如下图):

Here is how my curl login POST call looks like (I used Firebug + persist option to copy/paste the below):

curl --data-urlencode 'userName=tutu&password=xx' \
'https://thesite/api/login?noCacheDummyValue=1459356436185' -X POST \
 -H 'Host: thesite' \
 -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0' \
 -H 'Accept: application/json, text/plain, */*' \
 -H 'Accept-Language: en-US,en;q=0.7,fr-FR;q=0.3' \
 -H 'Accept-Encoding: gzip, deflate, br' \
 -H 'X-Requested-With: XMLHttpRequest' \
 -H 'Content-Type: application/json;charset=utf-8' \
 -H 'Referer: https://thesite/mobile/app/app.html' \
 -H 'Content-Length: 44' \
 -H 'Cookie: JSESSIONID=qhs02mfeip2p1n5n4t2rj1huu'

但是,这给我什么输出:

But this gives me nothing in the output:

 sh myproj.sh 
curl: (52) Empty reply from server

Q1:我应该从这个第一 POST收集,怎么办呢

我试图让与饼干 - 饼干-JAR cookie.txt ,但没有显示在我的当前目录。不过,我送饼干头......我不应该让他们回来?

Q1: What should I collect from this first POST, and how to do it?

I tried to get the cookie with --cookie-jar cookie.txt but nothing showed up in my current directory. However I sent cookies with the header... shouldn't I get them back?

之后,我想继续我(我想)打开,从得到的(同上的方法)收集数据会话:

After that I would like to continue the session I (think I) opened so to collect data from a GET that is (same method as above):

curl 'https://thesite/api/data/1036493/heatEnergy/today?noCacheDummyValue=1459356438440' \
     -H 'Host: thesite' \
     -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0' \
     -H 'Accept: application/json, text/plain, */*' \
     -H 'Accept-Language: en-US,en;q=0.7,fr-FR;q=0.3' \
     -H 'Accept-Encoding: gzip, deflate, br' \
     -H 'X-Requested-With: XMLHttpRequest' \
     -H 'Referer: https://thesite/mobile/dashboard/dash.html' \
     -H 'Cookie: JSESSIONID=qhs02mfeip2p1n5n4t2rj1huu'

Q2:如何保持打开执行上述 GET 会话

我试过 - 下一个选项想法从这里调用 GET POST ;没有成功, - 下一个选项无法识别我的Ubuntu Linux操作系统

Q2: How do I keep the session opened to perform the GETabove?

I tried --next option idea from here to call the GET after the POST; without success, --next option is not recognized on my Ubuntu Linux.

如果它可以帮助理解,我应该得到的页面是完整的JavaScript的( angularjs 我认为)。

If it can help understanding, the page I should get is full of javascript (angularjs I think).

您的帮助将大大AP preciated。

Your help would be greatly appreciated.

推荐答案

从你的 POST 称,很明显,你正在尝试做一个ajax XMLHtt prequest 。可能在期待JSON EN codeD数据。然而,你所提供的网址恩codeD数据。

From your POST call it is obvious that you are trying to do an ajax XMLHttpRequest. Likely this is expecting json encoded data. However you are providing url-encoded data.

也许你应该尝试使用的东西沿

Probably you should try using something along

... -X POST -H "Content-Type: application/json" -d '{"userName":"tutu","password":"xx"}' 'https://thesite/api/login?noCacheDummyValue=1459356436185'

要做出的登录的工作,你需要在服务器维护会话的方式相匹配。如果会话信息是通​​过cookie简称哟可能只是从中提取 POST 调用的cookie(如你所说,你试过了,但在一个错误的相关回应)

To make the login work, you need to match the way the server is maintaining the session. If session info is referred to via a cookie yo may just extract the cookie from the POST call (as you said you tried already, but on an error related response)

如果服务器不使用引用您的会话的直线方式让你的 GET 调用工作可能不会成功。如果你是幸运也许你那么就需要从网页(片段),或JSON数据解析返回一个字符串。

If the server does not use a straight way of referencing the session you might not succeed in getting your GET call working. If you are lucky maybe you then just need to parse a string from the page (fragment) or json data returned.

所以,监视哪些工作握手(使用浏览器例如)被交换过线。并尝试identifing数据的重要棋子。然后,把这些一起形成的GET电话。

So monitor what a working handshake (e.g using a browser) is exchanging over the wire. And try identifing the important pieces of data. Then, put those together to form your GET call.

这篇关于如何使用Linux的卷曲登录从其获取一次数据记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆