Почему этот запрос http post в AngularJS дает неожиданную ошибку токена?

0

Я могу успешно выполнить запрос HTTP-почты, используя следующие

curl --request POST
--url https://api.sendgrid.com/v3/mail/send
--header 'Authorization: Bearer xxxxxxxxxxxxx'
--header 'Content-Type: application/json'
--data '{"personalizations": [{"to": [{"email": "[email protected]"}]}],"from": {"email": "[email protected]"},"subject": "Hey","content": [{"type": "text/plain", "value": "Test"}]}'

Я попытался преобразовать это в угловой запрос HTTP, выполнив

            $http({
                method: 'POST',
                url: 'https://api.sendgrid.com/v3/mail/send',
                 headers: {
                    'Authorization: Bearer xxxxxxxxxxxx'
                },
                data: '{"personalizations": [{"to": [{"email": "[email protected]"}]}],"from": {"email": "[email protected]"},"subject": "Hey","content": [{"type": "text/plain", "value": "Test"}]}'
            }).
            success(function(data, status) {}).
            error(function(data, status) {});

Я получаю непредвиденную ошибку маркера на линии Authorization: Bearer.

Теги:

2 ответа

1

объект заголовков должен быть ключевым/значением объекта:

headers: {'Authorization': 'Bearer xxxxxx'}
  • 0
    хм, ты быстр, не замечаешь твой ответ
0

Вы забыли ' после 'Authorization'

headers: {'Authorization': 'Bearer xxxxxx'}

Запрос:

 $http({method: 'POST',
        url: 'https://api.sendgrid.com/v3/mail/send',
        headers: {
        'Authorization': 'Bearer xxxxxxxxxxxx'
        },
        data: '{"personalizations": [{"to": [{"email": "[email protected]"}]}],"from": {"email": "[email protected]"},"subject": "Hey","content": [{"type": "text/plain", "value": "Test"}]}'
        }).
        success(function(data, status) {}).
        error(function(data, status) {});

Ещё вопросы

Сообщество Overcoder
Наверх
Меню