本文整理汇总了TypeScript中@angular/common/http.HttpHeaders.set方法的典型用法代码示例。如果您正苦于以下问题:TypeScript HttpHeaders.set方法的具体用法?TypeScript HttpHeaders.set怎么用?TypeScript HttpHeaders.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/common/http.HttpHeaders
的用法示例。
在下文中一共展示了HttpHeaders.set方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(private http: HttpClient, configuration: Configuration) {
this.actionUrl = configuration.Server + 'api/things/';
this.headers = new HttpHeaders();
this.headers = this.headers.set('Content-Type', 'application/json');
this.headers = this.headers.set('Accept', 'application/json');
}
示例2: intercept
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
var token = localStorage.getItem('token'); //1
var newHeader: HttpHeaders = req.headers; //2
newHeader = newHeader.set('Content-Type', 'application/json'); //3
if(token) newHeader = newHeader.set('x-access-token', token); //4
const newReq = req.clone({headers: newHeader}); //5
return next.handle(newReq); //6
}
示例3: constructor
constructor() {
this.headers = new HttpHeaders();
this.headers = this.headers.set('Content-Type', 'application/json');
this.headers = this.headers.set('Accept', 'application/json');
this.authHeaders = new HttpHeaders();
this.authHeaders = this.headers;
this.authHeaders = this.authHeaders.append('Authorization', `Bearer ${this.getToken()}`);
}
示例4: getHeaders
getHeaders(token, contentType):any {
let headers:HttpHeaders = new HttpHeaders();
if(token){
headers = headers.set("Authorization", token.token_type + " " + token.access_token);
}
if(contentType){
headers = headers.set("Content-Type", contentType);
}
return headers;
}
示例5: constructor
constructor(
private services: Services
//private store: Store<any>,
//private oidcSecurityService: OidcSecurityService
) {
this.headers = new HttpHeaders();
this.headers = this.headers.set('Content-Type', 'application/json');
this.headers = this.headers.set('Accept', 'application/json');
this.init();
}
示例6: transformRequest
transformRequest() {
let headers = new HttpHeaders();
const headersObj = this.authenticationDataService.getRequestOptionsHeaders();
for (const h of Object.entries(headersObj)) {
headers = headers.set(h[0], h[1]);
}
return { headers: headers };
}
示例7: saveSkilltrees
public saveSkilltrees(skilltrees: Skilltree[]) {
let savedSkilltrees = [];
skilltrees.forEach(skilltree => {
let data: any = {ID: skilltree.id, Order: skilltree.order};
if (skilltree.name) {
data.Name = skilltree.name;
}
if (skilltree.requirements && skilltree.requirements.length > 0) {
data.Requirements = skilltree.requirements;
}
if (skilltree.icon) {
let icon: any = {};
let save = false;
if (skilltree.icon.material && skilltree.icon.material !== "") {
icon.Material = skilltree.icon.material;
save = true;
}
if (skilltree.icon.glowing) {
icon.Glowing = skilltree.icon.glowing;
save = true;
}
if (save) {
data.Icon = icon;
}
}
if (skilltree.inheritance && skilltree.inheritance.skilltree) {
let inheritance: any = {};
if (skilltree.inheritance.skilltree) {
inheritance.Skilltree = skilltree.inheritance.skilltree;
}
data.Inheritance = inheritance;
}
if (skilltree.requiredLevel) {
data.RequiredLevel = skilltree.requiredLevel;
}
if (skilltree.maxLevel) {
data.MaxLevel = skilltree.maxLevel;
}
if (skilltree.description) {
data.Description = skilltree.description.slice();
}
if (skilltree.weight && skilltree.weight != 1) {
data.Weight = skilltree.weight;
}
data.MobTypes = this.saveMobTypes(skilltree.mobtypes.slice(0));
data.Skills = {};
this.saveSkills(data.Skills, skilltree.skills);
this.saveNotifications(data, skilltree.messages);
savedSkilltrees.push(data);
});
let headers = new HttpHeaders();
headers = headers.set('Content-Type', 'application/json; charset=utf-8');
return this.http.post("/api/skilltrees/save", savedSkilltrees, {headers});
}
示例8: function
let authHeaders = function(headers?: HttpHeaders) : HttpHeaders {
headers = headers ? headers : new HttpHeaders();
return headers.set(
"Authorization", localStorage.getItem("token")
).set(
"Accept", "application/json"
);
}
示例9: createAntiForgeryTokenHeader
private createAntiForgeryTokenHeader(headers: HttpHeaders) {
const tokenElement = document.all['__RequestVerificationToken'];
if (!tokenElement) {
console.log('Error: AntiForgeryToken not found.');
return;
}
const token = tokenElement.defaultValue.toString();
return headers.set('__RequestVerificationToken', token);
}
示例10: uploadFile
uploadFile(data: FormData) {
const headers = new HttpHeaders();
headers.append('Content-Type', 'multipart/form-data');
// 'application/x-www-form-urlencoded;charset=utf-8'
headers.set('Accept', 'application/json');
return new HttpRequest('POST', '/upload', data, {
headers: headers,
reportProgress: true,
});
}