this.http.post请求返回403错误

时间:2016-10-25 19:46:41

标签: angularjs

我正在处理http.post请求。我试图通过网址发送一些数据。它适用于jmeter。但是没有在应用程序中工作。它给出403错误“angular.js:13424 SyntaxError:Unexpected token< in JSON in position 0”

scheduledMeetings : function(sessionId, arg, arg1, arg2, arg3, arg4, SuccessCallback, ErrorCallback){
    if(sessionId ){
        var config = {headers: {
                'authorization': sessionId,
                'accept': 'application/json'    
            }
        };

        this.http.post(
            bcs_config.api_url+'/partner/scheduling/srfsearchbycustomer?customerId='+arg+'&timeZoneId='+arg1+
            '&startDate='+arg2+'&endDate='+arg3+'&meetsStatus='+arg4,
            config).success(SuccessCallback).error(ErrorCallback);

    }else{
        console.error("AHelper.js - Call scheduledMeetings() failed:"," sessionId is empty!");
        return false;
    }

    return true;
}

1 个答案:

答案 0 :(得分:0)

如果您不发送数据,请使用GET而不是POST。如果您想在不使用任何数据的情况下使用帖子,请使用以下代码更改代码:

 $http.post(url, data, config)
            .success(function (data, status, headers, config) {
            })
            .error(function (data, status, header, config) {
            });

检查文档,你遗漏了一个数据逗号:

{
    "ctr": 57,
    "averageECPC": 23,
    "cost": 2732.54,
    "margin": 66,
    "profit": 2495.9,
    "property": {
        "value": "Izzby",
        "uri": "/Terrago/2"
    },
    "status": {
        "content": "<p>Some Content</p>",
        "stage": 1
    },
    "alerts": {
        "status": 2
    },
    "revenue": {
        "value": 2573.13,
        "compare": 0
    },
    "children": [{
        "ctr": 79,
        "averageECPC": 54,
        "cost": 3554.78,
        "margin": 88,
        "profit": 3145.81,
        "property": {
            "value": "Comvex",
            "uri": "/Octocore/4"
        },
        "status": {
            "content": "<p>Some Content</p>",
            "stage": 1
        },
        "alerts": {
            "status": 2
        },
        "revenue": {
            "value": 1247.92,
            "compare": 0
        }
    }]
}