在bash脚本中使用JavaScript的卷曲登录 [英] Javascript login using cURL in bash script
问题描述
我试图写,我需要登录到其使用JavaScript在形式上网站bash脚本。我从来没有使用卷曲,因此任何帮助将是AP preciated。我知道我需要使用cookies和我有HTTP头,但我不知道我需要这些做的。
I am trying to write a bash script in which I need to login to a website which uses javascript in its form. I have never used cURL so any help would be appreciated. I know I need to use cookies and I have the http headers, but I don't know what I need to do with these.
标头是
Response Headers
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Content-Length 0
Content-Type text/html;charset=UTF-8
Date Thu, 17 May 2012 11:25:15 GMT
Expires Tue, 01 Jan 1980 00:00:00 GMT
Last-Modified Thu, 17 May 2012 11:25:16 GMT
Pragma no-cache
Server Apache-Coyote/1.1
X-Powered-By Servlet 2.4; JBoss-4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)/JBossWeb-2.0
Request Headers
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection keep-alive
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Cookie SMLOGOUT=true; JSESSIONID=8D5757001A594D5CBB07C9250D1CB2B7; JSESSIONIDSSO=A0569CD1D6C981989F0FE691E9AFC314
Host https:/example.com
Referer https://example.com
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
X-WCF-Fragment true
任何帮助或指向我朝着正确的方向将是AP preciated。谢谢
Any help or pointing me in the right direction would be appreciated. Thanks
推荐答案
从请求头可以很容易地看到你发送一些后的数据。但你并没有提供它。我给你一个HTTP请求如何转化为curl命令一个简单的例子。
From the request header it can be easily seen that you are sending some post data. But you didn't provide it. I give you a simple example on how a http request can be converted to curl command.
假设你有这样的要求,你要留言2表单变量 VAR1
和 VAR2
得到发表于 http://www.example.com/form.url
。该请求是这样的,
Suppose you have this request where you are posting 2 form variables var1
and var2
get POSTed to http://www.example.com/form.url
. The request would look like this,
POST /form.url HTTP/1.1
Host: www.example.com
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
var1=val1&var2=val2
当其转换为卷曲它像
curl -d 'var1=val1&var2=val2' \
--header 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
--header 'Accept-Encoding gzip, deflate' \
--header 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
'http://www.example.com/form.url'
请注意:
-
这样就可以尽可能多添加你想要的标题。但它更好只添加这是必要的标头。因为
卷曲
将通过最头你(如主机
,用户代理
,内容类型
,接受
等)。
This way you can add as much as header you want. But its better you add only the headers which is necessary. Because
curl
will pass most headers for you (e.g.Host
,User-Agent
,Content-Type
,Accept
etc).
如果您要管理的cookie文件添加 cookie.txt
在当前目录和 -b cookie.txt -c饼干.TXT
命令开关卷曲。手段,
If you want to manage cookie add a file cookie.txt
in the current directory and -b cookie.txt -c cookie.txt
command switches to curl. Means,
-b/--cookie <name=string/file> Cookie string or file to read cookies from (H)
-c/--cookie-jar <file> Write cookies to this file after operation (H)
-d
开关表示将在请求体传递数据串。
-d
switch stands for the data string that will be passed in the request body.
-d/--data <data> HTTP POST data (H)
现在我希望你可以建立你的命令。
Now I hope you can build your command.
这篇关于在bash脚本中使用JavaScript的卷曲登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!