本文整理汇总了TypeScript中@angular/http.RequestOptions类的典型用法代码示例。如果您正苦于以下问题:TypeScript RequestOptions类的具体用法?TypeScript RequestOptions怎么用?TypeScript RequestOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RequestOptions类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: sendRequest
private sendRequest(url: string, options: RequestOptionsArgs): Observable<string> {
// make a copy
let options1 = new RequestOptions();
options1.method = options.method;
options1 = options1.merge(options);
let resource = this.adalService.GetResourceForEndpoint(url);
let authenticatedCall: Observable<string>;
if (resource) {
if (this.adalService.userInfo.isAuthenticated) {
authenticatedCall = this.adalService.acquireToken(resource)
.flatMap((token: string) => {
if (options1.headers == null) {
options1.headers = new Headers();
}
options1.headers.set('Authorization', 'Bearer ' + token);
return this.http.request(url, options1)
.catch(this.handleError);
});
}
else {
authenticatedCall = Observable.throw(new Error('User Not Authenticated.'));
}
}
else {
authenticatedCall = this.http.request(url, options).map(this.extractData).catch(this.handleError);
}
return authenticatedCall;
}
示例2: requestHelper
private requestHelper(requestArgs: RequestOptionsArgs, additionalOptions?: RequestOptionsArgs): Observable<Response> {
let options = new RequestOptions(requestArgs);
if (additionalOptions) {
options = options.merge(additionalOptions);
}
return this.request(new Request(options));
}
示例3: head
/**
* Get Head
* @param endPoint
* @param options
* @returns {Observable<Response>}
*/
public head(endPoint: string, options?: RequestOptions) : Observable<Response>{
let _options:RequestOptions = ApiAuth.createHttpOptions();
_options.url = Config.apiUrl + endPoint;
_options.method = RequestMethod.Head;
if (options) {
_options = _options.merge(options);
}
return this.requestHelper(_options)
}
示例4: patch
/**
* Patch a Resource
* @param endPoint
* @param body
* @param options
* @returns {Observable<Response>}
*/
public patch(endPoint: string, body: any, options?: RequestOptions) : Observable<Response>{
let _options:RequestOptions = ApiAuth.createHttpOptions();
_options.url = Config.apiUrl + endPoint;
_options.method = RequestMethod.Patch;
_options.body = JSON.stringify(body);
if (options) {
_options = _options.merge(options);
}
return this.requestHelper(_options)
}
示例5: find
/**
* Find a Resource
* @param endPoint
* @param params
* @param additionalOptions
* @returns {Observable<Response>}
*/
public find(endPoint: string, params:URLSearchParams, options?:RequestOptions) : Observable<Response>{
let _options:RequestOptions = ApiAuth.createHttpOptions();
_options.url = Config.apiUrl + endPoint;
_options.method = RequestMethod.Get;
_options.search = params;
if (options) {
_options = _options.merge(options);
}
return this.requestHelper(_options);
}
示例6: requestHelper
private requestHelper(additionalOptions?:RequestOptions){
this.loading.start(() => {
});
let options:RequestOptions = ApiAuth.createHttpOptions();
if (additionalOptions) {
options = options.merge(additionalOptions);
}
let req = this.http.request(new Request(options));
req.subscribe(res => this.HandleReponse(res), error => this.HandleError(error));
return req;
}
示例7: mergeOptions
private mergeOptions(options?: RequestOptionsArgs): RequestOptionsArgs {
const csrfToken: string = this.cookieService.get('XSRF-TOKEN');
let base: RequestOptions = new RequestOptions({
headers: new Headers({
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
'X-XSRF-TOKEN': csrfToken
})
});
// If we have a valid jwt token, we add it
if (this.tokenService.isValid()) {
base.headers.set('Authorization', 'Bearer ' + this.tokenService.token.access_token);
}
return base.merge(options);
}
示例8: requestHelper
private requestHelper(requestArgs: RequestOptionsArgs, additionalOptions?: RequestOptionsArgs): Observable<Response> {
console.log("Handling options...");
let options = new RequestOptions(requestArgs);
if (additionalOptions) {
options = options.merge(additionalOptions);
}
if (this.boxConfig.boxTokenCache) {
return this.boxConfig.boxTokenCache.getToken()
.mergeMap((token) => {
return this.requestWithToken(new Request(this.mergeOptions(options, this.defOpts)), token);
})
} else {
return this.boxConfig.refreshTokenFunction()
.mergeMap((token) => {
console.log("Refreshing token...");
console.log(token.json());
return this.requestWithToken(new Request(this.mergeOptions(options, this.defOpts)), token.json());
});
}
}
示例9: _request
_request(options: RequestOptionsArgs, auth?: boolean) {
if (auth) {
if (localStorage.getItem(this._config.tokenName)) {
this.defaultOptions.headers.set('Authorization', 'Bearer ' + localStorage.getItem(this._config.tokenName))
} else {
}
}
options.url = `${this.API_ENDPOINT}${options.url}`
return this.http.request(new Request(this.defaultOptions.merge(options)))
.map((res: any) => res.json())
}
示例10: delete
delete(url) {
return this.http
.delete(url, this.defaultOptions.merge({ url }))
.map(ShHttpService.onResponseSuccess);
}