【问题标题】:GET request working on Postman but not code on TerminalGET 请求在 Postman 上工作,但在终端上没有代码
【发布时间】:2020-08-02 21:07:01
【问题描述】:

我在 Postman 上运行 GET 并且在状态 200 的情况下运行良好,但是当我从 Postman 获取代码并在我的 Mac OS 终端上运行 Curl/Python 时出现 401 错误,请你帮我修复问题。

curl --location --request GET 'www.instacart.com/v3/containers/costco/next_gen/retailer_information/content/delivery?source=web' --header 'Cookie: _instacart_logged_in=1; build_sha=xxxxxxxxxxxxxx; signup_load_perf_date=xxxxxxxxxxxxxx;幅度_idundefinedinstacart.com=xxxxxxxxxxxxxx; _gcl_au=xxxxxxxxx; _fbp=fbxxxxxxxx;......'

{"error":{"message":"Unauthorized"},"meta":{"triggered_action":null}}

【问题讨论】:

    标签: python curl terminal postman


    【解决方案1】:

    您发布的命令部分似乎没问题。

    也许您错过了其他标题? 考虑到 cookie 也可能过期...

    更新:

    服务器可以禁止 curl 用户代理,所以尝试添加

    -H 'User-Agent: Mozilla' \
    

    另外,Postman 可能会自动附加 Content-Type 标头,因此请尝试添加

    -H 'Content-Type:application/json' \
    

    另一件事是检查主机。尝试使用https://,也可以使用/不使用www

    【讨论】:

    • 我用新的 cookie 反复测试了多次运行,我拿起的代码来自 postmaster 本身
    • @Kumar 我更新了我的答案,请尝试这两个补充
    • 如果我只添加 -H 'User-Agent: Mozilla' \ 我看到以下错误 % Total Received % Xferd Average Speed Time Time Time Current Dload Upload Total 花左速度 100 162 100 162 0 0 292 0 --:--:-- --:--:-- --:--:-- 292 100 69 0 69 0 0 77 0 --:--:-- --:-- :-- --:--:-- 77 curl: (6) 无法解析主机:Cookie
    • 看来你的主机不好。试试https://,也许有/没有www
    • 它就像一个魅力!!!!谢谢!!!! instacart.com/v3/containers/costco/next_gen/…
    猜你喜欢
    • 2022-01-12
    • 2020-02-23
    • 1970-01-01
    • 2019-03-12
    • 1970-01-01
    • 2020-05-02
    • 2020-05-26
    • 1970-01-01
    • 2016-07-03
    相关资源
    最近更新 更多