如何使用linux curl登录和检索数据一次记录? [英] How to use linux curl to login and retrieve data once logged?

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

问题描述

我有一个设备Stiebel Eltron热泵回家,我想使用 Linux shell curl (不是php)curl登录(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

这是我的curl登录POST调用看起来像(我使用Firebug + persist 选项复制/粘贴以下) / p>

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 ,怎么办?



我试图用 .txt ,但没有显示在我的当前目录中。但是我发送的cookie与标题...不应该让他们回来吗?

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?

之后,我想继续开会,我(我想)从GET中收集数据(与上述方法相同):

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



我尝试了 - 下选项从这里想法 POST 之后调用 GET 没有成功, - 下选项在我的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).

推荐答案

p>从你的 POST 调用很明显,你正在尝试做一个ajax XMLHttpRequest。可能这是期待json编码数据。

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.

可能应该尝试使用

... -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.

因此,监视什么是工作握手(例如使用浏览器)正在通过导线交换。并尝试识别重要的数据。然后,将它们组合起来形成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 curl登录和检索数据一次记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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