Outlook Rest调用表单angularjs

Outlook Rest调用表单angularjs,angularjs,rest,outlook,Angularjs,Rest,Outlook,我正在尝试使用outlook创建事件,当我使用POSTMAN发送请求时,它工作正常,但Angularjs中的相同代码不起作用。 代码有什么问题。 请帮忙 $scope.createEvents = function(){ var url = "https://outlook.office.com/api/v2.0/$metadata#Me/Calendars"; //var url = "https://outlook.office.com/api/v2.0/$metadata

我正在尝试使用outlook创建事件,当我使用POSTMAN发送请求时,它工作正常,但Angularjs中的相同代码不起作用。 代码有什么问题。 请帮忙

 $scope.createEvents = function(){
    var url = "https://outlook.office.com/api/v2.0/$metadata#Me/Calendars";
    //var url = "https://outlook.office.com/api/v2.0/$metadata#me/Calendars";

    var add_events = {
              "Subject": "Discuss the Calendar REST API",
              "Body": {
                "ContentType": "HTML",
                "Content": "I think it will meet our requirements!"
              },
              "Start": {
                  "DateTime": "2016-10-10T18:00:00",
                  "TimeZone": "Pacific Standard Time"
              },
              "End": {
                  "DateTime": "2016-10-10T19:00:00",
                  "TimeZone": "Pacific Standard Time"
              },
              "Attendees": [
                {
                  "EmailAddress": {
                    "Address": "sathish.gopikrishnan@stradegi.com",
                    "Name": "Sathish Gopi"
                  },
                  "Type": "Required"
                }
              ]
            };
    $http({
        method: 'POST',
        url: url,
        headers:{
            'Authorization':'Bearer '+$scope.token,
            'Content-Type': "application/json",
            'Accept': 'application/json;odata.metadata=minimal',
            'Access-Control-Allow-Origin':'*'            
        },          
        data: add_events
    }).Succes(function (response) {
        alert("Saved")
    });   
我越来越累了。
加载资源失败:服务器响应状态为406(不可接受)。为了解决这个问题,我现在使用这个代码

$scope.createEvents = function(){
var url = "https://outlook.office.com/api/v2.0/$metadata#Me/Calendars";
//var url = "https://outlook.office.com/api/v2.0/$metadata#me/Calendars";

var add_events = {
          "Subject": "Discuss the Calendar REST API",
          "Body": {
            "ContentType": "HTML",
            "Content": "I think it will meet our requirements!"
          },
          "Start": {
              "DateTime": "2016-10-10T18:00:00",
              "TimeZone": "Pacific Standard Time"
          },
          "End": {
              "DateTime": "2016-10-10T19:00:00",
              "TimeZone": "Pacific Standard Time"
          },
          "Attendees": [
            {
              "EmailAddress": {
                "Address": "sathish.gopikrishnan@stradegi.com",
                "Name": "Sathish Gopi"
              },
              "Type": "Required"
            }
          ]
        };
$http({
    method: 'JSONP',
    url: url,
    headers:{
        'Authorization':'Bearer '+$scope.token,
        'Content-Type': "application/json",
        'Accept': 'application/json;odata.metadata=minimal',
        'Access-Control-Allow-Origin':'*'            
    },          
    data: add_events
}).Succes(function (response) {
    alert("Saved")
});
在使用Jsonp作为方法之后,我得到了这个错误


未捕获的语法错误:意外标记406不可接受的定义如下:

根据请求中发送的accept标头,由请求标识的资源只能生成具有不可接受内容特征的响应实体

您发送以下接受标头:

'Accept': 'application/json;odata.metadata=minimal'
服务器说,它无法生成此内容类型。如果您使用postman运行它,请查看您在那里提供的accept标头

关于第二次尝试:jsonp不是http方法/动词(GET、PUT、POST、DELETE、PATCH)。我不是angularjs专家,但如果您需要jsonp,可以调用一个


JSONP是一种非常特殊(而且有点问题)的技术。所以,只要你能做到这一点,尽量避免它。

我知道这是一篇老文章,我也遇到过同样的问题,如果有人遇到同样的问题,这就是解决办法, 您应该使用作为URL

示例测试代码:

  var url = "https://graph.microsoft.com/v1.0/me/calendar/events";

     var add_events = {
                                          "Subject": "Title",
                                          "Body": {
                                            "ContentType": "HTML",
                                            "Content": " Exemple"
                                          },
                                          "Start": {
                                              "DateTime": "2010-05-17T18:00:00",
                                              "TimeZone": "UTC"
                                          },
                                          "End": {
                                              "DateTime": "2010-05-17T19:00:00",
                                              "TimeZone": "UTC"
                                          }
                                        };
     $http({
          method: 'POST',
          url: url,
          headers:{
                                           'Authorization':'Bearer '+localStorage.getItem('Your Token here'),
                                           'Content-Type':'application/json',
                                           'Accept': 'application/json;odata.metadata=minimal',
                                           'Access-Control-Allow-Origin':'*',
                                           'token_type':'Bearer'
                                       },
                                       data: add_events
                                     }).then(function successCallback(response) {

                                        console.log(response);

                                       }, function errorCallback(response) {

                                         localStorage.setItem('etat_mytoken', 0);
                                         $window.location.href =  url_base+'/'+url_base_v+'/app/assets/views/token.html';


                                       });

您是否检查了“开发工具”中“网络”选项卡中的请求详细信息?加载资源失败:服务器响应状态为406(不可接受)。谢谢,相同的代码不是用js编写的,而是用java编写的,工作正常。