我有一个奇怪的问题,试图连接到API,当我尝试在Postman或Insomnia中执行API请求时,一切都可以。当我在网站上甚至在Local -Host上使用相同的代码时...

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

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> var settings = { "async": true, "crossDomain": true, "url": "https://affiliate-api.tradingcrm.com:4477/token", "method": "POST", "data": "{ userName: \"alpt\", password: \"Alpt@12345\" }" } $.ajax(settings).done(function (response) { var settings2 = { "async": true, "crossDomain": true, "url": "https://affiliate-api.tradingcrm.com:4477/accounts/lead", "method": "POST", "headers": { "Authorization": "Bearer " + response.Token, "Api-Version": "3", "Content-Type": "application/json" }, "data": "{firstName:\"test\",lastName:\"test2\",email:\"[email protected]\"}" } $.ajax(settings2).done(function (response2) { console.log(response2.accountId); }); }); </script>

enter image description hereITSCORS

问题,API服务器缺少标头
javascript jquery postman
1个回答
5
投票
因此您无法设置自定义请求标头,例如,解决方案使用CORS代理或从服务器中检索数据或要求提供商添加它。

与Postman不同的IS Postman不询问Server API,它只是仅发送标题,而"Api-Version": "3",因为在提出请求之前,它会通过执行以下标题来询问的不同域。

Browser
然后服务器API需要使用标题

OPTIONS

CORS代理测试:


Post


	

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.