旧行李 2015-11-20 21:23 采纳率: 25%
浏览 30

通过$ http发布获取404

csMgmtApp.controller('launchedController', ['$scope', '$http', '$document', '$resource', function ($scope, $http, $document, $resource) {

    $scope.clientResult = {};
    $scope.data = {};

    $document.ready(function () {
        var query_string = {};
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            query_string[pair[0]] = pair[1];
        }
        if (typeof(query_string.access_token) != "undefined") {
            var result = {};
            result.state = query_string.state;
            result.scope = query_string.scope;
            result.access_token = query_string.access_token;
            result.expires_in = query_string.expires_in;
            result.resource_server_base_uri = query_string.resource_server_base_uri;
            result.token_type = query_string.token_type;
        }

        $scope.clientResult = result;

    });

    console.log($scope.clientResult);

        $scope.startSessionPayload = {
            'stationPhoneNumber': '5555555555',
            'inactivityTimeout': '0',
            'inactivityForceLogout': 'false'
        };

    $http({
        'url': $scope.clientResult.resource_server_base_uri  + 'services/v6.0/agent-sessions',
        'method': 'POST',
        'headers':{'Authorization': 'bearer ' + $scope.clientResult.access_token,'content-Type': 'application/json'},
        'data': JSON.stringify($scope.startSessionPayload)
    }).success(function(data, status, headers, config) {
        $scope.data = data;
        console.log('data', $scope.data)
    }).error(function(data, status, headers, config) {
        $scope.status = status;
    });

}]);

The code above gives me a 404 when I try te $http "POST".

When I console.log($scope.clientResult.resource_server_base_uri), I get: "https%3a%2f%2fapi-c7.incontact.com%2finContactAPI%2f".

But, I get a 404, and when I look in developer tools, I see it's trying to post to : "http://localhost:63342/Call_cntr/client/https%3a%2f%2fapi-c7.incontact.com%2finContactAPI%2fservices/v6.0/agent-sessions"

I'm starting to think it's failing because the "://localhost..." is being "prepended" to the base_uri... Not sure why this is happening. I feel I'm providing everything mentioned in the inContact API docs. Maybe it's with my angular conversion from AJAX to $http ??

Any help, much appreciated, I'm stuck..

Once you have an API Authentication Token, you use this token to create an agent session for the agent whose credentials you used to get the token. This is done by requesting the https://api-{cluster}.incontact.com/inContactAPI/services/v6.0/agent-sessions method, and supplying either a "station ID" or a phone number which will be delivered to the agent.

per the docs : https://developer.incontact.com/API/AgentAPI#!/Sessions/startSession

  • 写回答

1条回答 默认 最新

  • weixin_33681778 2015-11-20 21:32
    关注

    Try

    result.resource_server_base_uri = unescape(query_string.resource_server_base_uri);
    

    I believe that / is actually a seperator, but %2f becomes an ordinary character that simply represents / character in your url.

    unescape() is deprecated; try decodeURIComponent()

    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图