2013-07-02 40 views
0

有人能告诉我为什么我的命令不起作用吗?wget未设置Cookie

这里是我的形式:

<form id="query" method="POST" action="https://weblogin.mycompany.com/" 
enctype="application/x-www-form-urlencoded" autocomplete="off"> 
<table border="0" align="center"> 
<tr> 
<td class="fieldname">Username:</td> 
<td><input type="text" name="user" size="20" value="" class="inputfield" /> </td> 
</tr> 
<tr> 
<td class="fieldname">Password:</td> 
<td><input type="password" name="pass" class="inputfield" /></td> 
</tr> 
<tr> 
<td class="fieldname"></td> 
<td><input type="submit" value="Log in &raquo;" /></td> 
</tr> 
</table> 
<div id='notifyuser'></div> 
</form> 

这里是我的wget命令:

%的wget --save饼干/tmp/cookies.txt --post数据“用户=添加my_id & pass = my_passwd'\ https://weblogin.mycompany.com/

当我执行上面的wget命令后,cookie文件是空的。

% cat /tmp/cookies.txt 
# HTTP cookie file. 
# Generated by Wget on 2013-07-02 16:23:39. 
# Edit at your own risk. 

和HTTP响应:

% wget --keep-session-cookies --save-cookies /tmp/wget03_cookies.txt --post-data 'user=my_id&pass=my_passwd' **https://weblogin.mycompany.com/** 
--2013-07-03 09:52:06-- https://weblogin.mycompany.com/ 
Resolving weblogin.mycompany.com... 1.1.1.1 
Connecting to weblogin.mycompany.com|1.1.1.1|:443... connected. 
HTTP request sent, awaiting response... 200 OK 
Length: 4477 (4.4K) [text/html] 
Saving to: `index.html.10' 

100%[===========================================================================>] 4,477  --.-K/s in 0s 

2013-07-03 09:52:06 (36.8 MB/s) - `index.html.10' saved [4477/4477] 

我做了什么错?


我可能会发现在这个线程解决方案:wget with authentication

解决的办法是这样的:

#!/bin/sh 

# get the login page to get the hidden field data 
wget -a log.txt -O loginpage.html http://foobar/default.aspx 
hiddendata=`grep value < loginpage.html | grep foobarhidden | tr '=' ' ' | awk '{print $9}' | sed s/\"//g` 
rm loginpage.html 

# login into the page and save the cookies 
postData=user=fakeuser'&'pw=password'&'foobarhidden=${hiddendata} 
wget -a log.txt -O /dev/null --post-data ${postData} --keep-session-cookies --save-cookies cookies.txt http://foobar/default.aspx 

# get the page your after 
wget -a log.txt -O results.html --load-cookies cookies.txt http://foobar/lister.aspx?id=42 
rm cookies.txt 

我不明白的是 - 那我该怎么用在产生hiddendata的同时替代'foobarhidden'?

我相信下面的部分应该给我答案。但我不知道究竟该做什么:

% grep value < loginpage.html | grep hidden 
3:109:<input type=hidden name=pubcookie_g_req value="b25lPWFsb2hhLmFrYW1haS5jb20mdHdvPWFsb2hhJnRocmVlPTEmZm91cj1hNWEmZml2ZT1HRVQmc2l4PWFsb2hhLmFrYW1haS5jb20mc2V2ZW49THc9PSZlaWdodD0mYWthX2ZyYWc9Jmhvc3RuYW1lPWFsb2hhLmFrYW1haS5jb20mbmluZT0xJmZpbGU9JnJlZmVyZXI9KG51bGwpJnNlc3NfcmU9MCZwcmVfc2Vzc190b2s9NjMzMzQ0OTI3JmZsYWc9MA=="> 
4:110:<input type=hidden name=post_stuff value=""> 
5:111:<input type=hidden name=relay_url value="https://weblogin.mycompany.com/PubCookie.reply"> 

谢谢!!

+1

从服务器回来的HTTP响应中有什么?也许有错误返回? – RichieHindle

+0

顺便说一下,我的wget的版本是1.12。 –

+0

谢谢@RichieHindle我会在'回答'区域发布回复,因为这里放的时间太长。再次感谢。 –

回答

0

在你的问题中,你说你连接到https://...,但在你的日志里是http://... - 也许这就是问题所在?确保您在命令行上使用https://...

+0

谢谢你指出,@RichieHindle!我用https重试它,结果是一样的。同样,该消息将被发布在答案区域。另外,页面'weblogin.mycompany.com'中有很多javascript代码。这会导致wget停止工作吗?再次感谢! –

+0

@CharlieYen:您应该将新信息编辑到问题中,而不是将其作为答案发布。 – RichieHindle

+0

谢谢你告诉我,@RichieHindle。仍然是这个论坛的新手。对于不遵守规则感到抱歉。我将删除应答区域中的新信息并更新原始信息。再次感谢。 –