【问题标题】:Request works from Postman but not from cURL请求来自邮递员,但不是来自 cURL
【发布时间】:2017-12-06 22:24:33
【问题描述】:

我有一个非常简单的 Postman 请求,它在 Postman 中运行良好。这只是对以下 URL 的 GET 请求:

http://www.toysrus.com/storefrontsearch/stores.jsp?skuId=24654884&quantity=1&postalCode=48103&latitude&longitude&productId=107531766&startIndexForPagination=0&searchRadius=0&pageType=product&ispu_or_sts=null&displayAllStoresFlag=false&displayAllStoreLink=false

如果我让 Postman 为我提出一个 cURL 请求,它会给我这个:

curl -X GET \ 'http://www.toysrus.com/storefrontsearch/stores.jsp?skuId=24654884&quantity=1&postalCode=48103&latitude=&longitude=&productId=107531766&startIndexForPagination=0&searchRadius=0&pageType=product&ispu_or_sts=null&displayAllStoresFlag=false&displayAllStoreLink=false' \ -H 'cache-control: no-cache' \ -H 'postman-token: b4ae79c0-c3f0-8247-8c2f-306c43376039'

结果是它永远挂起,从来没有给我任何回应。

知道可以做些什么来使 cURL 请求正常工作吗?

【问题讨论】:

  • 更新:我发现 GET 请求在 Postman 中可以正常工作,我相信这会稍微简化问题。
  • 然后从卷曲线上去掉-X GET...
  • 就像我说的,我的curl 命令直接来自 Postman。我推断无论-X GET 是否存在,该命令在功能上都是等效的,因此删除它不会改变任何东西。 (我尝试了没有-X GET 的命令,只是为了确保我没有发疯,并且请求似乎以同样的方式失败。)
  • 您的网址无效。它重定向到 404 页面
  • URL 确实有效。

标签: curl postman


【解决方案1】:

小心饼干怪物

并非所有 Postman 请求都是平等的。

Postman 将存储 cookie whether you like it or not(并在随后对同一域的调用中将它们发送过来)。

我没有意识到我对同一个域的第一次调用收到了一个 cookie,该 cookie 在 Postman 的下一次调用中发回。所以即使一切看起来都一样,我并没有通过 curl 发送 cookie。

【讨论】:

    【解决方案2】:

    似乎服务器已经禁止 curl 用户代理,还需要设置 cookie troute=t1 否则返回 404:

    curl -L -H 'User-Agent: Mozilla' \
            -H 'Cookie: troute=t1;' \
            'http://www.toysrus.com/storefrontsearch/stores.jsp?skuId=24654884&quantity=1&postalCode=48103&latitude&longitude&productId=107531766&startIndexForPagination=0&searchRadius=0&pageType=product&ispu_or_sts=null&displayAllStoresFlag=false&displayAllStoreLink=false' --compressed
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-28
      • 1970-01-01
      • 1970-01-01
      • 2020-08-10
      • 2018-01-11
      • 2016-10-23
      • 2021-01-10
      • 1970-01-01
      相关资源
      最近更新 更多