jquery - 尝试获取作业结果在 Postman 中完美运行,但在浏览器中使用 AJAX 需要 app_code 和 app_id

标签 jquery ajax postman here-api

我正在尝试使用 HERE job REST API 来获取我的作业结果。我在 Postman 中测试了 GET 请求,它使用我的 apiKey 完美运行,无需使用任何额外的 header (Content-Type:application/octet-stream 除外)。

Postman Request

但是当我尝试使用 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/

相关文章:

ios - Alamofire - 错误的请求

javascript - JQuery UI 自动完成 - 当用户单击文本框时打开菜单

javascript - 显示正在加载图像直到 div 完全加载

javascript - 向一个特定的 li 元素添加一个类

jquery - 如何优化将大量元素动态添加到网页中

azure-devops - 以编程方式更新 postman 集合

javascript - AJAX 请求适用于 .click() 但不适用于 .submit()

javascript - 在 JavaScript 中递归调用 Web 服务会导致 StackOverflow

php - jQuery 阻止所有表单同时提交

postman - postman 请求正文中的文件未保存在集合中