gpt4 book ai didi

api - postman 为 POST 请求解析 "Invalid CORS request"

转载 作者:行者123 更新时间:2023-12-03 13:27:27 29 4
gpt4 key购买 nike

我刚刚开始使用 Postman 来测试我正在集成的 API。

我有以下错误不断出现

Invalid CORS request



请注意以下事项:
  • API 使用不记名 token 身份验证 (OAuth2)。我有这个
    工作没有问题。
  • 我确实成功获得了不记名 token ,将其分配给环境变量,然后尝试将其用于 RESTful 操作。
  • 问题出在使用 token 的后续 RESTful 操作中。
  • 当我使用旧 token (通过 POST 操作)时,它理所当然地
    告诉我它已过期且未授权。
  • 当我生成一个新的并尝试运行 restful 调用时,它给了我 Invalid CORS request错误。
  • 使用 cURL,我没有问题。但是 postman 让我很沮丧 .

  • 到目前为止我发现了什么:
  • Using postman with Http POST requests - 我没有看到粗体的部分

  • Just in case anybody else has this same problem, here is how to solve it. Go to https://www.getpostman.com/docs/capture in your chrome browser. Click on interceptor extension and then choose add to chrome. Once it is added there is a new icon top right of both the browser and postman that looks like a traffic light. In postman click this and it turns green. Then add a header to every request going to third light. Every header consists of the header name and a value. Start typing over the header name and a list of allowed http headers comes up. Choose "Origin". In the cell for value simply type the full URL of your server. (Do not forget the 'http://' or 'https://').


  • What is the expected response to an invalid CORS request? - 迄今为止我看到的关于 CORS 错误的最佳解释。

  • 其他 Material 讲 Access-Control-Allow-Method header , preflight requests
    ... 还有一个 CORS 流程的说明性 Apache Tomcat 流程图。

    enter image description here

    最佳答案

    这是您再次找到的答案:

    Just in case anybody else has this same problem, here is how to solve it. Go to https://www.getpostman.com/docs/capture in your chrome browser. Click on interceptor extension and then choose add to chrome. Once it is added there is a new icon top right of both the browser and postman that looks like a traffic light. In postman click this and it turns green.



    ... 用粗体字翻译:

    Then add a header to your request. The header Key should be "Origin" and the header Value should be the full URL of your server (Do not forget the http:// or https://).



    请注意,如果没有 Interceptor 插件,Chrome/Postman 将不允许您添加带有 Key of Origin 的 Header。

    另请注意,至少在我的系统上,拦截器图标不再像交通灯。

    关于api - postman 为 POST 请求解析 "Invalid CORS request",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38778083/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com