我可以使用以下
成功执行HTTP post请求Configuration Manager
我尝试通过
将其转换为角度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": "xxx@yahoo.com"}]}],"from": {"email": "xxx@yahoo.com"},"subject": "Hey","content": [{"type": "text/plain", "value": "Test"}]}'
我在 $http({
method: 'POST',
url: 'https://api.sendgrid.com/v3/mail/send',
headers: {
'Authorization: Bearer xxxxxxxxxxxx'
},
data: '{"personalizations": [{"to": [{"email": "xxx@yahoo.com"}]}],"from": {"email": "xxx@yahoo.com"},"subject": "Hey","content": [{"type": "text/plain", "value": "Test"}]}'
}).
success(function(data, status) {}).
error(function(data, status) {});
行上收到意外的令牌错误。
答案 0 :(得分:1)
headers对象应该是键/值对象:
headers: {'Authorization': 'Bearer xxxxxx'}
答案 1 :(得分: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": "xxx@yahoo.com"}]}],"from": {"email": "xxx@yahoo.com"},"subject": "Hey","content": [{"type": "text/plain", "value": "Test"}]}'
}).
success(function(data, status) {}).
error(function(data, status) {});