本文整理匯總了TypeScript中angular2/http.Headers.set方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Headers.set方法的具體用法?TypeScript Headers.set怎麽用?TypeScript Headers.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類angular2/http.Headers
的用法示例。
在下文中一共展示了Headers.set方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: beforeEach
beforeEach(() => {
matcher = new RequestMatcher(res());
headers = new Headers();
headers.set('pass', '123');
headers.set('passAgain', ['1', '2', '3']);
request = req({ url: '', headers });
});
示例2: RequestOptions
const mergeAuthToken = (options:RequestOptionsArgs) => {
let newOptions = new RequestOptions({}).merge(options);
let newHeaders = new Headers(newOptions.headers);
newHeaders.set('x-auth-token', localStorage.getItem('jwt'));
newHeaders.set('accept', 'application/json');
newHeaders.set('content-type', 'application/json');
newOptions.headers = newHeaders;
return newOptions;
};
示例3: RequestOptions
const mergeAuthToken = (options:RequestOptionsArgs) => {
let newOptions = new RequestOptions({}).merge(options);
let newHeaders = new Headers(newOptions.headers);
let auth = JSON.parse(localStorage.getItem('auth'));
if(auth!==null) {
let access_token = auth.access_token;
let token = auth.token_type+' '+ access_token;
localStorage.setItem('token', token);
newHeaders.set('Authorization', token);
newHeaders.set('Accept', 'application/json');
newHeaders.set('Content-Type', 'application/json');
}
newOptions.headers = newHeaders;
return newOptions;
};
示例4: RequestOptions
const mergeAuthToken = (options:RequestOptionsArgs) => {
let newOptions = new RequestOptions({}).merge(options);
let newHeaders = new Headers(newOptions.headers);
newHeaders.set('x-auth-token', localStorage.getItem('jwt'));
newOptions.headers = newHeaders;
return newOptions;
};
示例5: save
save(userModel:User){
console.log('service called');
var myHeaders:Headers = new Headers();
myHeaders.set("content-type",'application/json');
return this.http.post('/users',JSON.stringify(userModel),{
headers:myHeaders
});
}
示例6: auth
auth(username: string, password: string): Observable<string> {
let headers = new Headers();
headers.set('Content-Type', 'application/json');
let opts = new RequestOptions({ headers: headers });
let body = JSON.stringify({ username: username, password: password });
return this.http.post('http://localhost:8080/auth', body, opts)
.map(res => res.json())
.map(json => json.token);
}
示例7: save
save(flug: Flug) {
var headers = new Headers();
headers.set('Content-Type', 'text/json')
var url = "http://www.angular.at/api/flug";
return this.http
.post(url, JSON.stringify(flug), {headers})
.map(resp => resp.json());
}
示例8: findById
findById(id: string) {
var search = new URLSearchParams();
search.set('flugNummer', id);
var headers = new Headers();
headers.set('Accept', 'text/json')
var url = "http://www.angular.at/api/flug";
return this.http
.get(url, {search, headers})
.map(resp => resp.json());
}
示例9: getHeaders
private getHeaders(useToken:boolean = true):Headers {
let headers = new Headers({
"Content-Type": "application/json",
"X-Requested-With": "XMLHttpRequest",
});
if (useToken) {
let token = Cookie.getCookie(CONSTANTS.CSRF_NAME);
if (token) {
headers.set("X-CSRFToken", token);
}
}
return headers;
}