我正在尝试使用 HERE job REST API 来获取我的作业结果。我在 Postman 中测试了 GET 请求,它使用我的 apiKey 完美运行,无需使用任何额外的 header (Content-Type:application/octet-stream 除外)。
但是当我尝试使用 AJAX 和 jQuery 尝试相同的请求时,我收到 400 响应,告诉我我需要 app_id 和 app_code。 我的代码:
$.ajax({
async: false,
contentType: "application/octet-stream",
type: 'GET',
url: "https://batch.geocoder.ls.hereapi.com/6.2/jobs/{JOB_ID}/result?apiKey={API_KEY}",
}).done(function (result) {
console.log(result);
});
返回 header :
{"error":"Bad Request","error_description":"The request is missing the app_id and app_code parameters. They must both be passed as query parameters. If you do not have app_id and app_code, please obtain them through your customer representative or at http://developer.here.com/myapps."}
将这个普通链接放入浏览器的地址栏中时,它确实有效。
使用https://developer.here.com/projects/上的应用程序ID的组合REST 和 apikey 下的页面,因为 api_code 也不起作用。这告诉我这是一个无效的对。
我不知道我现在应该实际使用什么凭据。
感谢您提前提供的帮助!
最佳答案
根据 documentation您必须使用apikey
进行身份验证。
请检查此 ajax 代码,该代码工作正常。
<html>
<button type="button" class="btn">Click me!</button>
<p class="text">Replace me!!</p>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
$('.btn').click(function() {
$('.text').text('loading . . ');
$.ajax({
type:"GET",
url:"https://batch.geocoder.ls.hereapi.com/6.2/jobs/CxnGVvxLZeCjJnGRD0udKgLgeQzNa5xq/result?apiKey={apikey}",
success: function(result) {
$('.text').text(JSON.stringify(result));
console.log(result);
},
});
});
</script>
</html>
希望这有帮助。
关于jquery - 尝试获取作业结果在 Postman 中完美运行,但在浏览器中使用 AJAX 需要 app_code 和 app_id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59643322/