本文整理汇总了TypeScript中@angular/http.Headers.set方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Headers.set方法的具体用法?TypeScript Headers.set怎么用?TypeScript Headers.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/http.Headers
的用法示例。
在下文中一共展示了Headers.set方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: writeRequest
writeRequest(request: IN, options: RequestOptionsArgs): RequestOptionsArgs {
const opts = new RequestOptions(options).merge({body: JSON.stringify(request)});
let headers: Headers;
if (opts.headers) {
headers = opts.headers;
} else {
opts.headers = headers = new Headers();
}
headers.set("Content-Type", "application/json");
return opts;
}
示例2: get
/**
* Wrapper for HTTP GET operation
*/
public get(url: string, paramsMap?: Map<any, any>): Observable<any> {
this._headers.set("Cache-Control", "no-cache");
let options = new RequestOptions({headers: this._headers});
if (paramsMap) {
const requestParams: URLSearchParams = new URLSearchParams();
paramsMap.forEach((key, value) => {
requestParams.set(key, value);
});
options = new RequestOptions({headers: this._headers, search: requestParams});
}
return this._http
.get(this._baseUrl + url, options)
.map(response => this.mapResponse(response))
.catch(error => this.handleError(error));
}
示例3: doRequest
private doRequest(resource:string, call_method:APICallMethod, params:Object, need_authorized:boolean)
{
if (need_authorized && this.token_ === null) {
// TODO raise error
return;
}
let full_url = this.url_ + resource;
let headers = new Headers();
let options = new RequestOptions();
options.headers = headers;
// TODO Optimize condition
if (call_method == APICallMethod.Post) {
headers.set("Content-Type", "application/json");
options.method = RequestMethod.Post;
let params_json_str = JSON.stringify(params);
options.body = params_json_str;
}
else if (call_method == APICallMethod.Get) {
headers.set("Content-Type", "");
options.method = RequestMethod.Get;
options.body = "";
}
else if (call_method == APICallMethod.Delete) {
headers.set("Content-Type", "text/plain");
options.method = RequestMethod.Delete;
options.body = "";
}
this.logger_.info("[APIService]doRequest", full_url, call_method);
return this.http_.request(full_url, options)
.map(resp => this.extractData(resp))
.catch(error => this.handleError(error));
}
示例4: find
// Array<Flight>, Flight[]
find(from: string, to: string): Observable<Flight[]> {
let url = "http://www.angular.at/api/flight";
let headers = new Headers();
headers.set('Accept', 'text/json');
let search = new URLSearchParams();
search.set('from', from);
search.set('to', to);
return this.http
.get(url, { headers,search })
.map(resp => resp.json());
}
示例5: find
public find(from: string, to: string) {
let url = "/data/flights.json";
var search = new URLSearchParams();
search.set('from', from);
search.set('to', to);
var headers = new Headers();
headers.set('Accept', 'text/json');
return this.http
.get(url, { search, headers })
.map(resp => resp.json())
}
示例6: Promise
return new Promise(resolve => {
let url = ApiConfig[url_path];
url = options.id? url + options.id: url;
url = options.category_id? url + "?category_id=" + options.category_id: url;
if(options.ids){
url = url + "?";
for(let i = 0; i < options.ids.length; i++) {
url = url + "id=" + options.ids[i] + "&&";
}
}
let headers = new Headers();
headers.set('Authorization', "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIyfHVuZGVmaW5lZCIsInN1YiI6InN1YmplY3QiLCJhdWQiOiJzYWlscy13YXRlcmxvY2stdG9rZW4tdGVtcGxhdGUiLCJleHAiOjE0Njg5ODU4NzYxNzgsIm5iZiI6MTQ2ODM4MTA3NjE3OCwiaWF0IjoxNDY4MzgxMDc2MTc4LCJqdGkiOiIyZmU4ZWIyMC00OGFiLTExZTYtODVkYi1jMTk5ZGI3NDAzYWIifQ.Eey2ffNAdRf179JeEjWg2vizZSR1sQTqmlzneqR3RQU");
let opt: RequestOptions;
opt = new RequestOptions({
headers: headers
});
this.http.get(url, opt)
.map(res => {
if(res.status < 200 || res.status >= 300) {
// this.nav.push(LoginPage);
}
// If everything went fine, return the response
else {
return res.json();
}
})
.subscribe(data => {
console.log(url)
resolve(data);
}, err => {
console.log("Response ERROR:")
console.log(err);
// let prompt = Alert.create({
// message: JSON.parse(err._body).error,
// buttons: [{text: "Ok"}]
// });
// this.nav.present(prompt);
resolve(err);
});
});
示例7: postFile
//Bekommt als Name die ID des Nutzers auf dem jwt Ăźbergeben, diese wird als Name der Datei verwendet
//http-Modul von Angular unterstĂźtzt das multipart Format aktuell nicht daher xhr
postFile(inputValue: any, name: string, pfad:string): void {
var formData = new FormData();
formData.append("name", name);
formData.append("pfad", pfad);
formData.append("file", inputValue.files[0]);
var headers = new Headers();
headers.set('Content-Type', 'multipart/form-data');
let xhr = new XMLHttpRequest();
xhr.open('POST', Path[0]+'/upload', true);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.withCredentials = false;
xhr.send(formData);
}
示例8: getAuthHeaders
getAuthHeaders(): Headers {
let headers = new Headers({'Content-Type': 'application/x-www-form-urlencoded'});
headers.set('authorization', this.getToken());
return headers;
}
示例9: setAuthorizationHeader
private setAuthorizationHeader(headers: Headers) {
headers.set('Authorization', this.authService.getRequestHeaderValue());
}
示例10: addAuthorizationData
public addAuthorizationData(token: string): void {
this.headers.set("Authorization", "Bearer " + token);
}