corspost请求失败_邮递员解决“无效的CORS请求” POST请求

I've just started using Postman to test an API I am integrating to.

I have the following error that keeps showing up

Invalid CORS request

Note the following:

The API uses Bearer token authentication(OAuth2). I have this

working without a problem.

I do get the bearer token successfully, assign it to an Environment variable and then attempt to use it for the RESTful operations.

The problem is in the subsequent RESTful operation that uses the token.

When I use an old token (through a POST operation), it rightfully

tells me that it is expired and not authorized.

When I then generate a new one and try to run the restful call, it gives me that Invalid CORS request error.

Using cURL, I have no issues. But I am frustrated by Postman.

What I have found so far:

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://').

The other material speaks about Access-Control-Allow-Method header, preflight requests

... and there is an illustrative Apache Tomcat flowchart of the CORS flow.

解决方案

Here's the answer you found again:

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.

... With the bit in bold translated:

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://).

Note that Chrome/Postman won't allow you to add a Header with a Key of Origin without the Interceptor plugin.

Also note that at least on my system the Interceptor icon no longer looks like a traffic light.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值