Anuja Patil Anuja Patil - 1 month ago 9
AngularJS Question

this.http.post request returns 403 error

I am working on a

http.post
request. I am trying to send some data through the url. It works with jmeter. But is not working in the application. It gives 403 error with "angular.js:13424 SyntaxError: Unexpected token < in JSON at 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;
}

Answer

If you are not sending data, use GET instead of POST. If you want to use post without any data change your code with:

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

check the documentation, you miss one comma for data:

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