AngularJS在发送请求时更改定义的标头

时间:2016-02-27 01:23:01

标签: javascript angularjs json ionic-framework

我正在运行angularjs应用程序,但我无法找到为什么我的$ http调用更改了我的请求标题。

我将我想要的标题定义为'accept': 'application/JSON'。但是当我查看请求标题时,我看到Accept: */*

我的代码是:

.controller('StopDetailCtrl', function($scope, $http) {
    $scope.info = fetch();

  function fetch(){
        var uriBuilder = 'http://api.translink.ca/rttiapi/v1/stops/55612?apikey=u8RWYB3HmxjsHenpDk0u'

    $http({
          method: 'JSONP',
          url: uriBuilder,
          headers: {
            'Accept': 'application/JSON'
          }
        }).then(function successCallback(response) {
          console.log('Success', JSON.stringify(response));
        }, function errorCallback(response) {
          console.log('Error', JSON.stringify(response));
        });
    }
})

uri确实返回一个值,但它是XML,导致抛出错误。 我一直回来的错误是一个json字符串:

    {
  "status": 404,
  "config": {
    "method": "JSONP",
    "transformRequest": [
      null
    ],
    "transformResponse": [
      null
    ],
    "url": "http:\/\/api.translink.ca\/rttiapi\/v1\/stops\/55612?apikey=Y3pJJjLVyfPetMoowJP4",
    "headers": {
      "Accept": "application\/json, text\/plain, *\/*"
    }
  },
  "statusText": "error"
}

网络开发控制台告诉我请求标头是:

Referer:    http://localhost:8100/?restart=125748
Accept: */*
Cache-Control:  max-age=0

Accept: */*与我放置headers: {'Accept': 'application/JSON'}

的标题不同

我使用的api是:https://developer.translink.ca/ServicesRtti/ApiReference

0 个答案:

没有答案
相关问题