在 FedEx 与 React 集成时,我们可以使用 Google 扩展获取授权密钥,但无法使用其他 API。所有 API 在邮递员中都可以完美工作,但在集成时则不然。尝试检查费率和运输时间,但收到 CORS 错误。我已经包含了代码和错误屏幕截图。您能帮忙吗?
let body = JSON.stringify({
"accountNumber": {
"value": "XXXXXXXXX"
},
"requestedShipment": {
"shipper": {
"address": {
"postalCode": 75063,
"countryCode": "US"
}
},
"recipient": {
"address": {
"postalCode": "L0J 0A0",
"countryCode": "CA"
}
},
"pickupType": "DROPOFF_AT_FEDEX_LOCATION",
"serviceType": "FEDEX_GROUND",
"rateRequestType": [
"LIST",
"ACCOUNT"
],
"customsClearanceDetail": {
"dutiesPayment": {
"paymentType": "SENDER",
"payor": {
"responsibleParty": null
}
},
"commodities": [{
"description": "Camera",
"quantity": 1,
"quantityUnits": "PCS",
"weight": {
"units": "KG",
"value": 20
},
"customsValue": {
"amount": 100,
"currency": "USD"
}
}]
},
"requestedPackageLineItems": [{
"weight": {
"units": "KG",
"value": 20
}
}]
}
});
axios.post("https://apis-sandbox.fedex.com/rate/v1/rates/quotes", body, {
headers : {
"Accept": "*/*",
"Content-Type": "application/json",
"authorization": `Bearer XXX`,
"Access-Control-Allow-Origin": "*",
}
}).then(res => console.log(res.data));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
Cors错误无法从前端解决,因为它是浏览器错误。所以你必须创建代理服务器来解决这个问题 在后端创建一个 API 并将请求从服务器发送到 fedex。
您是否在没有联系 Fedex IT 部门来配置您的 cors 策略的情况下解决了这个问题?同样的问题在这里:)