curl:如何通过命令行发送cookie? [英] curl: how to send cookies via command line?
本文介绍了curl:如何通过命令行发送cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我读到发送带curl的Cookie 可以使用,但不适用于我
我有一个 REST
端点为
class LoginResource(restful.Resource):
def get(self):
print(session)
如果'USER_TOKEN'在会话中:
return'OK'$当我尝试以 $访问时,b $ b返回'未授权',401
b
$ b
curl -v -b〜/ Downloads / cookies.txt -c〜/ Downloads / cookies.txt http://127.0.0.1:5000/
*关于连接()到127.0.0.1端口5000(#0)
*尝试127.0.0.1 ...
*连接
*连接到127.0.0.1 .0.1)port 5000(#0)
> GET / HTTP / 1.1
> User-Agent:curl / 7.27.0
>主机:127.0.0.1:5000
>接受:* / *
>
* HTTP 1.0,假定在body之后关闭
< HTTP / 1.0 401 UNAUTHORIZED
< Content-Type:application / json
< Content-Length:16
<服务器:Werkzeug / 0.8.3 Python / 2.7.2
<日期:Sun,14 Apr 2013 04:45:45 GMT
<
*关闭连接#0
未授权%
code>〜/ Downloads / cookies.txt 是
cat〜 .txt
USER_TOKEN = in
且服务器什么也不收。
127.0.0.1 - - [13 / Apr / 2013 21:43:52]GET / HTTP / 1.1401 -
127.0.0.1 - - [13 / Apr / 2013 21:45:30]GET / HTTP / 1.1401 -
< SecureCookieSession {}>
< SecureCookieSession {}>
127.0.0.1 - - [13 / Apr / 2013 21:45:45]GET / HTTP / 1.1401 -
$ b
解决方案
这适用于我
curl -v --cookieUSER_TOKEN = Yeshttp://127.0.0.1:5000/
我可以使用
查看后端的值。
print request.cookies
I read that Send cookies with curl works, but not for me
I have a
REST
endpoint asclass LoginResource(restful.Resource): def get(self): print(session) if 'USER_TOKEN' in session: return 'OK' return 'not authorized', 401
when I try to access as
curl -v -b ~/Downloads/cookies.txt -c ~/Downloads/cookies.txt http://127.0.0.1:5000/ * About to connect() to 127.0.0.1 port 5000 (#0) * Trying 127.0.0.1... * connected * Connected to 127.0.0.1 (127.0.0.1) port 5000 (#0) > GET / HTTP/1.1 > User-Agent: curl/7.27.0 > Host: 127.0.0.1:5000 > Accept: */* > * HTTP 1.0, assume close after body < HTTP/1.0 401 UNAUTHORIZED < Content-Type: application/json < Content-Length: 16 < Server: Werkzeug/0.8.3 Python/2.7.2 < Date: Sun, 14 Apr 2013 04:45:45 GMT < * Closing connection #0 "not authorized"%
where my
~/Downloads/cookies.txt
iscat ~/Downloads/cookies.txt USER_TOKEN=in
and the server receives nothing
127.0.0.1 - - [13/Apr/2013 21:43:52] "GET / HTTP/1.1" 401 - 127.0.0.1 - - [13/Apr/2013 21:45:30] "GET / HTTP/1.1" 401 - <SecureCookieSession {}> <SecureCookieSession {}> 127.0.0.1 - - [13/Apr/2013 21:45:45] "GET / HTTP/1.1" 401 -
what is that I am missing?
解决方案This worked for me
curl -v --cookie "USER_TOKEN=Yes" http://127.0.0.1:5000/
I could see the value in backend using
print request.cookies
这篇关于curl:如何通过命令行发送cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文