Httpie: 支持cookie?

创建于 2012-03-06  ·  6评论  ·  资料来源: httpie/httpie

是否支持cookie?

底层请求库似乎支持cookie。

干杯,

戈文达

question

最有用的评论

是的,您可以像其他所有标题一样指定cookie:

$ http GET httpbin.org/cookies Cookie:hello=world
HTTP/1.1 200 OK
Content-Type: application/json
Date: Tue, 06 Mar 2012 13:19:45 GMT
Server: gunicorn/0.13.4
Content-Length: 43
Connection: keep-alive

{
    "cookies": {
        "hello": "world"
    }
}

(另请参阅#13。)

你是这个意思吗?

所有6条评论

是的,您可以像其他所有标题一样指定cookie:

$ http GET httpbin.org/cookies Cookie:hello=world
HTTP/1.1 200 OK
Content-Type: application/json
Date: Tue, 06 Mar 2012 13:19:45 GMT
Server: gunicorn/0.13.4
Content-Length: 43
Connection: keep-alive

{
    "cookies": {
        "hello": "world"
    }
}

(另请参阅#13。)

你是这个意思吗?

@jakubroztocil我想知道服务器设置的cookie是否可以在通话中持久保存? 这在httpie可能吗? 因此,例如,我可以使用它来测试基于会话的api调用...

@mcnemesis是的,有一个会话功能,允许cookie以及自定义标头和auth在请求之间保留。

太棒了! 谢谢@jakubroztocil

@jakubroztocil我们可以使用json设置cookie吗?
{'MOODLEID1_': '%250xxx5C2', 'MoodleSession': 'btsmxxxxxxxosn7'}

@NightMachinary可以使用会话文件(https://httpie.org/docs#sessions):

使用cookies

$ cat  my-session.json
{
    "cookies": {
        "MOODLEID1_": {
            "value": "%250xxx5C2"
        },
        "MoodleSession": {
            "value": "btsmxxxxxxxosn7"
        }
    },
}
$ http --session ./my-session.json httpbin.org/headers
GET / HTTP/1.1
Cookie: MOODLEID1_=%250xxx5C2; MoodleSession=btsmxxxxxxxosn7

使用headers

$ cat  my-session.json
{
    "headers": {
        "Cookie": {
            "MOODLEID1_=%250xxx5C2; MoodleSession=btsmxxxxxxxosn7"
        }
    }
}
$ http --session ./my-session.json httpbin.org/headers
GET / HTTP/1.1
Cookie: MOODLEID1_=%250xxx5C2; MoodleSession=btsmxxxxxxxosn7
此页面是否有帮助?
0 / 5 - 0 等级

相关问题

eliangcs picture eliangcs  ·  5评论

poskadesign picture poskadesign  ·  7评论

mattotodd picture mattotodd  ·  3评论

a-x- picture a-x-  ·  7评论

maciej picture maciej  ·  4评论