本文整理匯總了TypeScript中angular2/http.Response.text方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Response.text方法的具體用法?TypeScript Response.text怎麽用?TypeScript Response.text使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類angular2/http.Response
的用法示例。
在下文中一共展示了Response.text方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: DOMParser
.map((res: Response) => {
let dom = (new DOMParser()).parseFromString(res.text(), "text/xml");
let json = xml2json(dom, "");
let cert = "-----BEGIN CERTIFICATE-----" + JSON.parse(json).EntityDescriptor[0]["ds:Signature"]["KeyInfo"]["X509Data"]["X509Certificate"] + "-----END CERTIFICATE-----";
let key = KEYUTIL.getKey(cert);
return KJUR.jws.JWS.verifyJWT(token, key, { alg: ['RS256'] });
})
示例2: Array
// Http Success
(res:Response) => {
if (res.status === 200) {
this.currentData = (res.text() !== '') ? res.json() : [{data: new Array(), group: new Array()}];
}
},
示例3: handleSignInResponse
// handles the sign-in response.
private handleSignInResponse(res: Response): Promise<WinkUser> {
console.log("Sign in response status: " + res.status);
if (res.status !== 200) {
this.user.isSignedIn = false;
console.log("Error: failed to sign in: \n" + res.text());
return Promise.reject<WinkUser>(res);
}
else {
this.user = JSON.parse(res.text());
this.user.isSignedIn = true;
console.log("Success: Signed in!");
return Promise.resolve<WinkUser>(this.user);
}
}
示例4: handleError
private handleError (error: Response) {
console.error('http error');
console.error(error);
let errorText = error.text();
if (error.status == 200) {
errorText = 'The whole server is down. The connection has been refused.';
}
return Observable.throw(errorText || 'Server error');
}
示例5: error
error (res: Response) {
let error;
if (!(res instanceof Response)) {
error = JSON.stringify(res);
} else if (res.status >= 300) {
error = 'Unexpected result.';
if (res.status == 404) {
error = res.text() || 'Resource not found';
} else if (res.status == 400) {
error = res.text() || 'Request could not be processed.';
} else if (res.status == 401) {
error = res.text() || 'Not authorized.';
} else if (res.status == 403) {
error = "You're not allowed to be here. Contact support for more information.";
} else if (res.status == 500) {
error = 'There was a problem with the server; try again later or contact support if the issue persists.';
}
}
return Observable.throw(error);
}
示例6:
this.httpProvider.getRequest('/src/mocks/map.json').subscribe(// Http Success
(res:Response) => {
if (res.status === 200) {
if (res.text() !== '') {
this.map = res.json();
this.currentMap = this.map[0];
this.currentSubMap = {};
}
}
},
示例7: tryParseErrorResponse
tryParseErrorResponse(err:Response):any {
let body:string = err.text();
if(_.isEmpty(body)) {
return body;
}
try {
return err.json();
} catch(e) {
return body;
}
}
示例8: handleEnumerateDevicesResponse
// handles the enumerate devices response.
private handleEnumerateDevicesResponse(res: Response, idKeyFilter: string): Promise<WinkDevice[]> {
console.log("Enumerate devices response status: " + res.status);
if (res.status !== 200) {
this.user.isSignedIn = false;
console.log("Error: failed to enumerate devices: \n" + res.text());
return Promise.reject<WinkDevice[]>(res);
}
else {
let response: WinkDeviceEnumerationResponse = JSON.parse(res.text());
// filter down to devices that have the specified ID Key filter
// (e.g. light_bulb_id if we are looking for lightbulbs)
this.devices = response.data.filter((WinkDevice) => {
return !!WinkDevice[idKeyFilter];
});
console.log("Success: Devices enumerated");
return Promise.resolve<WinkDevice[]>(this.devices);
}
}
示例9: handleError
// TODO Change to handleError service
private handleError(error: Response) {
// in a real world app, we may send the error to some remote logging infrastructure
// instead of just logging it to the console
console.error(error);
return Observable.throw(error.text() || 'Server error');
}
示例10:
.then((res:Response) =>
{
console.log('\n'+res.text());
this.regsuccess = true;
});