在开发中,这可行,但在生产标题中没有设置。
不确定这是一个角度用户错误还是nginx.conf问题。
var authentication = ('Basic ' + window.btoa('USERNAME:MYAPIKEY'));
$http.defaults.headers.common.Authorization = authentication;
$http.defaults.headers.common['Content-Type'] = 'application/json';
var payload = {some: 'data'};
$http({
url: 'https://some-end-point',
data: JSON.stringify(payload),
method: 'POST'
})
当我提交表单时,在开发内容类型和授权标头中设置。在生产中,两者都没有提出要求。
- 编辑
我正在记录错误,错误对象有这些标题,但是从浏览器发出的请求没有。我错过了什么?
带有请求标头的字符串化响应
"{\"data\":null,\"status\":-1,\"config\":{\"method\":\"POST\",\"transformRequest\":[null],\"transformResponse\":[null],\"url\":\"https://MYENDPOINT\",\"data\":{\"some\":\"data\"},\"withCredentials\":true,\"headers\":{\"Accept\":\"application/json, text/plain, */*\",\"Authorization\":\"Basic VVNFUk5BTUU6TVlBUElLRVk=\",\"Content-Type\":\"application/json;charset=utf-8\"}},\"statusText\":\"\"}"