在bash脚本使用卷曲的Javascript登录(Javascript login using cU

2019-06-24 13:14发布

我试图写在我需要登录到其使用JavaScript在形式上网站bash脚本。 我从来没有使用卷曲所以任何帮助,将不胜感激。 我知道我需要使用cookies和我有HTTP头,但我不知道我需要这些做。

标头是

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

任何帮助或指向我的方向是正确的,将不胜感激。 谢谢

Answer 1:

从请求头可以很容易地看到你发送一些后数据。 但你没有提供它。 我给你一个HTTP请求如何转化为curl命令一个简单的例子。

假设你有这样的要求,你要留言2表单变量var1var2才能发布到http://www.example.com/form.url 。 该请求是这样的,

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'

注意:

  1. 这样就可以增加多达头你想要的。 但它更好只添加这是必要的标头。 因为curl会通过你最头(如HostUser-AgentContent-TypeAccept等)。

  2. 如果你要管理的cookie文件添加cookie.txt在当前目录和-b cookie.txt -c cookie.txt命令开关卷曲。 手段,

     -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) 
  3. -d开关手段,将在请求体被传递的数据串。

     -d/--data <data> HTTP POST data (H) 

现在,我希望你可以建立你的命令。



Answer 2:

在HTTP中,有将数据发送到一个URL的方式有两种:

  • POST
  • 得到

GET,该数据被作为URL的一部分。 您可能会看到类似如下的URL:

http://foo.com/bar/barfoo/script.js?param1=this&param2=that&param3=the_other

此URL是在将数据发送到一个JavaScript http://foo.com/bar/barfoo/script.js 。 它发送给这个脚本以下参数:

  • param1 = this
  • param2 = that
  • param3 = the_other

POST操作,将数据发送不同,并在URL本身没有编码。 使用Web表单时(像你正在尝试做的),这种情况很多。 您可以使用--form参数curl通过POST数据就像你在一个HTTP表单字。

来自卷边管理:

-F/--form <name=content>
    (HTTP) This lets curl emulate a filled-in form in which a user has
    pressed the submit  button.  This  causes  curl  to  POST  data using
    the Content-Type multipart/form-data according to RFC 2388. This
    enables uploading of binary files etc. To force the 'content' part to
    be  a  file, prefix the file name with an @ sign. To just get the
    content part from a file, prefix the file name with the symbol <. The
    difference between @ and <  is  then  that  @  makes  a  file  get
    attached  in  the  post as a file upload, while the < makes a text
    field and just get the contents for that text field from a file.


Example, to send your password file to the server, where 'password' is the
name of  the  form- field to which /etc/passwd will be the input:

    curl -F password=@/etc/passwd www.mypasswords.com

To  read content from stdin instead of a file, use - as the filename. This
goes for both @ and < constructs.

You can also tell curl what Content-Type to use by using 'type=', in a
manner similar to:

    curl -F "web=@index.html;type=text/html" url.com

  or

    curl -F "name=daniel;type=text/foo" url.com

You can also explicitly change the name field of a file upload part by
setting filename=, like this:

    curl -F "file=@localfile;filename=nameinpost" url.com

希望这个对你有帮助。



Answer 3:

很抱歉,但卷曲不会做的JavaScript。

考虑

  • 手动破译javascript和在一个Perl /红宝石/ python脚本复制行为
  • 采用硒


文章来源: Javascript login using cURL in bash script