我正在使用Angular 2和webpack。 我遇到的问题是头参数的第一个字母自动转换为小写。例如
Accept': 'application/json, text/plain
转换为
accept':'application/json, text/plain
pakage.json
{
"name": "life-inventory",
"version": "1.0.0",
"description": "Life lazy loading",
"scripts": {
"start": "webpack-dev-server --inline --progress --port 8080",
"build": "rimraf dist && webpack --config config/webpack.prod.js --progress --profile --bail",
"postinstall": "typings install"
},
"license": "MIT",
"dependencies": {
"@angular/common": "2.0.0",
"@angular/compiler": "2.0.0",
"@angular/core": "2.0.0",
"@angular/forms": "2.0.0",
"@angular/http": "2.0.0",
"@angular/platform-browser": "2.0.0",
"@angular/platform-browser-dynamic": "2.0.0",
"@angular/router": "3.0.0",
"angular2-materialize": "^6.7.2",
"core-js": "^2.4.1",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.40",
"vue-router": "^2.5.2",
"zone.js": "^0.6.23"
},
"devDependencies": {
"@types/jquery": "^2.0.41",
"angular2-router-loader": "^0.2.2",
"angular2-template-loader": "^0.4.0",
"awesome-typescript-loader": "^3.0.0-beta.17",
"angular2-materialize": "^6.7.2",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.23.1",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.8.5",
"html-loader": "^0.4.3",
"html-webpack-plugin": "^2.15.0",
"jasmine-core": "^2.4.1",
"karma": "^1.2.0",
"karma-jasmine": "^1.0.2",
"karma-phantomjs-launcher": "^1.0.2",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.8.0",
"phantomjs-prebuilt": "^2.1.7",
"raw-loader": "^0.5.1",
"reflect-metadata": "^0.1.8",
"rimraf": "^2.5.2",
"style-loader": "^0.13.1",
"ts-loader": "^0.8.1",
"typescript": "2.3.4",
"typings": "^1.3.2",
"webpack": "^1.13.0",
"webpack-dev-server": "^1.14.1",
"webpack-merge": "^0.14.0"
}
}
我的请求文件是
import {Injectable} from '@angular/core';
import {Headers, Http, URLSearchParams, Response} from "@angular/http";
private headers = new Headers({
'content-Type': 'application/json',
'Accept': 'application/json, text/plain, */*'
});
addToken() {
if (jQuery.jStorage.get('currentUser')) {
this.token = jQuery.parseJSON(jQuery.jStorage.get('currentUser')).token;
this.headers.set('csToken', this.token);
this.headers2.set('csToken', this.token);
this.username = jQuery.parseJSON(jQuery.jStorage.get('currentUser')).username;
}
}
getDashboard(): Promise<Gast[]> {
this.addToken();
const url = `${this.apiUrl}/Dashboard?format=json`;
debugger
return this.http.get(url, {headers: this.headers})
.toPromise()
.then(response => response.json().data as Gast[])
.catch(this.handleError);
}
我尝试过使用.set
&amp;标头的.append
方法,但它不起作用。
答案 0 :(得分:0)
如果您的标题位于camelcase或upper中,则无关紧要。理想情况下应该没关系。 Http实现应该不区分大小写。如果在您的情况下确实重要,请检查后端团队是否已正确实施apis代码。