Wget 保存 cookie 不起作用

Try*_*ast 7 linux nas wget cookies

我一直在尝试通过 web api 登录 pyload,但是 wget 没有保存 cookie,我不明白为什么。

我正在使用以下命令:

wget --delete-after --keep-session-cookies --save-cookies=my_cookies.txt --post-data="username=USERNAME&password=PASSWORD" http://localhost:8000/api/login
Run Code Online (Sandbox Code Playgroud)

但是 my_cookies.txt 的内容是:

# HTTP cookie file.
# Generated by Wget on 2012-06-23 22:31:33.
# Edit at your own risk.
Run Code Online (Sandbox Code Playgroud)

当我运行相同的命令但在调试模式下时,我得到以下输出,其中包括标头响应中的设置 cookie:

DEBUG output created by Wget 1.10.2 (Red Hat modified) on linux-gnueabi.

--22:31:11--  http://localhost:8000/api/login
Resolving localhost... 127.0.0.1
Caching localhost => 127.0.0.1
Connecting to localhost|127.0.0.1|:8000... connected.
Created socket 3.
Releasing 0x000504d0 (new refcount 1).

---request begin---
POST /api/login HTTP/1.0
User-Agent: Wget/1.10.2 (Red Hat modified)
Accept: */*
Host: localhost:8000
Connection: Keep-Alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 32

---request end---
[POST data: username=USERNAME&password=PASSWORD]
HTTP request sent, awaiting response...
---response begin---
HTTP/1.1 200 OK
Content-Length: 34
Content-Type: application/json
Cache-Control: no-cache, must-revalidate
Set-cookie:  beaker.session.id=405390ddc809efed54820638c95d7997; expires=Tue, 19-Jan-2038 04:14:07 GMT; Path=/
Connection: Keep-Alive
Date: Sat, 23 Jun 2012 21:31:11 GMT
Server: CherryPy/3.1.2 WSGI Server

---response end---
200 OK
hs->local_file is: login (not existing)
Registered socket 3 for persistent reuse.
TEXTHTML is on.
Length: 34 [application/json]
Saving to: `login'

100%[=======================================>] 34          --.-K/s   in 0s

22:31:11 (1.28 MB/s) - `login' saved [34/34]

Removing file due to --delete-after in main():
Removing login.
Saving cookies to my_cookies.txt.
Done saving cookies.
Run Code Online (Sandbox Code Playgroud)

谁能告诉我我做错了什么?

小智 9

使用--keep-session-cookies的会话cookie不会保存在默认情况下


lor*_*nix 2

考虑到您仍在使用版本 1.10.2,您可能会遇到一个错误,该错误已在 2009 年 8 月的版本 1.12 中修复。您确实应该考虑升级,特别是因为最新版本是 1.13.4,于 2011 年 9 月附近发布。

无论如何...所讨论的错误是:bugGNU Wget - Bugs: bug #26775, Save cookies from non-200 returns,其中涉及 wget 在收到非 200 返回错误代码时不保存 cookies。

您的非调试请求很可能正在被缓存或发生其他情况,或者涉及 302 重定向...所有这些都会导致请求返回非 200 返回代码。您的调试输出确实显示 200-OK 代码...您是否使用与执行“正常”请求时完全相同的命令行来执行调试请求?