superagent Access-Control-Allow-Origin错误[重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我正在使用superagent v3.8.3我得到了Access-Control-Allow-Origin CORS错误。

import request from 'superagent'
request(
        APIS.IAMPORT.GET_TOKEN.method,
        APIS.IAMPORT.GET_TOKEN.path()
      )
        .withCredentials()
        .send({
          imp_key: config.iamport.apiKey,
          imp_secret: config.iamport.secretKey
        })
        .end((err, res) => {
          if (err) reject(err)
          else resolve(res.body)
        })

我试图使用.withCredentials(),但它不起作用。我从api收到此错误消息。

apply?id = 21:1来自'https://api.iamport.kr/users/getToken'的'http://localhost:8080'访问XMLHttpRequest已被CORS策略阻止:对预检请求的响应未通过访问控制检查:否'Access-Control-Allow-Origin'标头是出现在请求的资源上。

但是,当我使用邮差时,我可以得到结果。

我认为删除OPTION http方法会起作用。但我不知道如何解决这个问题。

怎么解决这个?谢谢。

http cors superagent http-method
1个回答
0
投票

问题不在于HTTP方法。问题是CORS,并试图在另一个答案中解释原因和解决方案。请参考以下链接:

https://stackoverflow.com/a/54867814/6356369

© www.soinside.com 2019 - 2024. All rights reserved.