本文整理匯總了TypeScript中@angular/http.Http.request方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Http.request方法的具體用法?TypeScript Http.request怎麽用?TypeScript Http.request使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@angular/http.Http
的用法示例。
在下文中一共展示了Http.request方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: addRecord
addRecord(input: any, params: string[]){
if(params[2] == "file"){
var re = /\\/gi;
var blacklist = input.blacklist? input.blacklist:"";
var logFilePath = input.log_file_path;
blacklist = blacklist.replace(re, "\\\\");
logFilePath = logFilePath.replace(re, "\\\\");
var data = getDataHeader(false)
+ getDataPair("log_file_path", logFilePath, false) + ","
+ getDataPair("sourcetype", input.sourcetype, false) + ","
+ getDataPair("log_file_size", input.log_file_size, false) + ","
+ getDataPair("data_retention_period", input.data_retention_period, false) + ","
+ getDataPair("memo", input.memo, false) + ","
+ getDataPair("env", input.env, false) + ","
+ getDataPair("user_name", input.user_name, false) + ","
+ getDataPair("app_id", input.app_id, true) + ","
+ getDataPair("blacklist", blacklist, false) + ","
+ getDataPair("crcsalt", input.crcsalt, false)
+ getDataTail(false);
var options = getRequestOption(RequestMethod.Post, inputUrl + "?env=" + params[0] + "&user=" + params[1] + "&type=" + params[2], data);
return this.http.request(new Request(options)).map((res: Response) => {
});
}else if(params[2] == "script"){
var formData = new FormData();
formData.append('script', input.script, input.script_name);
formData.append('sourcetype', input.sourcetype);
formData.append('log_file_size', input.log_file_size);
formData.append('data_retention_period', input.data_retention_period);
formData.append('env', input.env);
formData.append('user_name', input.user_name);
formData.append('os', input.os);
// formData.append('app_id', input.app_id);
formData.append('interval', input.interval);
formData.append('exefile', input.exefile);
formData.append('script_name', input.script_name);
formData.append('option', input.option);
var options = getBlobRequestOption(RequestMethod.Post, inputUrl + "?env=" + params[0] + "&user=" + params[1] + "&type=" + params[2], formData);
return this.http.request(new Request(options)).map((res: Response) => {
});
}else if(params[2] == "unixapp"){
var data = "[";
for (var i = 0; i < input.length; i++){
if (i != 0) {
data += ',';
}
data += getDataHeader(false);
data += getDataPair("script_name", input[i].script_name, false) + ",";
data += getDataPair("env", input[i].env, false) + ",";
data += getDataPair("user_name", input[i].user_name, false) + ",";
data += getDataPair("app_id", input[i].app_id, true) + ",";
data += getDataPair("interval", input[i].interval, false) + ",";
data += getDataPair("data_retention_period", input[i].data_retention_period, false);
data += getDataTail(false);
}
data += "]";
var options = getRequestOption(RequestMethod.Post, inputUrl + "?env=" + params[0] + "&user=" + params[1] + "&type=" + params[2], data);
return this.http.request(new Request(options)).map((res: Response) => {
});
}
}
示例2: getRecords
getRecords(envUserFrom: string[]){
var options = getRequestOption(RequestMethod.Get, forwarderUrl + "?env=" + envUserFrom[0] + "&user=" + envUserFrom[1] + "&from=" + envUserFrom[2], "");
// var options = getRequestOption(RequestMethod.Get, forwarderUrl, "");
return this.http.request(new Request(options))
.map((res:Response) => res.json())
;
}
示例3: GetRequest
public GetRequest(url: string): any {
return this.http.request(new Request(this.getRequsetOptions(url)))
.map((res: Response) => {
let jsonObj: any;
if (res.status === 204) {
// toastr.warning('No Content Found !');
jsonObj = null;
}
else if (res.status === 500) {
// toastr.error('Data Is not Present For Now !');
jsonObj = null;
}
else if (res.status !== 204) {
// toastr.success('Data Fetched From Server');
jsonObj = res.json()
}
return [{ status: res.status, json: jsonObj }]
})
.catch(error => {
if (error.status === 403) {
// toastr.error("You don't Have Permission to Access this Page!");
return Observable.throw(new Error(error.status));
}
else if (error.status === 400) {
// toastr.error("Bad Request! 400");
return Observable.throw(new Error(error.status));
}
});
}
示例4: 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;
}
示例5: saveSubject
saveSubject(subject: Subject) {
let request: Request = new Request({
url: "/api/subject/",
headers: authHeaders(),
body: JSON.stringify(subject)
});
if (subject._id) {
// _id exists - update user
request.method = RequestMethod.Put;
request.url += subject.code;
} else {
// create new subject
request.method = RequestMethod.Post;
}
return this.http.request(request).map((res) => {
if (res.status === 200 || res.status === 201) {
// Subject saved
return res.json();
} else {
// Error
console.error(res);
return null;
}
});
}
示例6: ajaxRaw
public ajaxRaw(requestOptions: RequestOptions): Promise<any> {
requestOptions.url = this.serviceUrl(requestOptions.url);
return this.http.request(new Request(requestOptions))
.toPromise()
.catch(error => this.handleAjaxError(error));
}
示例7: createDeploymentServerClass
createDeploymentServerClass(deploymentServerClasses: DeploymentServerClass[]){
var data = "[";
for (var i = 0; i < deploymentServerClasses.length; i++){
var forwarders = '"forwarder_names":[';
for (var j = 0; j < deploymentServerClasses[i].forwarder_names.length; j++) {
if (j != 0) {
forwarders += ',';
}
forwarders += getDataHeader(false);
forwarders += getDataPair("name", deploymentServerClasses[i].forwarder_names[j], false);
forwarders += getDataTail(false);
}
forwarders += ']';
if (i != 0) {
data += ',';
}
data += getDataHeader(false);
data += getDataPair("server_class_name", deploymentServerClasses[i].server_class_name, false) + ",";
data += getDataPair("app_name", deploymentServerClasses[i].app_name, false) + ",";
data += getDataPair("app_id", deploymentServerClasses[i].app_id, true) + ",";
data += getDataPair("user", deploymentServerClasses[i].user, false) + ",";
data += getDataPair("env", deploymentServerClasses[i].env, false) + ",";
data += forwarders;
data += getDataTail(false);
}
data += "]";
var options = getRequestOption(RequestMethod.Post, deploymentUrl + "/create_server_class", data);
return this.http.request(new Request(options)).map((res: Response) => {
});
}
示例8: deleteUser
//Delete user from backend with identifier
deleteUser(userId: string){
//Setup url parameters
let params = new URLSearchParams();
params.set("userId", userId);
//Make http delete request
var request = this.http.request(new Request(new RequestOptions({
method: RequestMethod.Delete,
url: "/api/v1/users",
search: params
})));
//Parse json response
return request
.map(res => res.json())
.map(res => {
//Check response for errors
if (res.hasOwnProperty('error')){
throw new Error(res.error);
}else{
return res;
}
});
}
示例9: insertUser
//Create new user in backend
insertUser(username: string, email: string){
//Make http post request
var request = this.http.request(new Request(new RequestOptions({
headers: new Headers({
"Content-Type": "application/json"
}),
method: RequestMethod.Post,
url: "/api/v1/users",
body: JSON.stringify({
username: username,
email: email
})
})));
//Parse json response
return request
.map(res => res.json())
.map(res => {
//Check response for errors
if (res.hasOwnProperty('error')){
throw new Error(res.error);
}else{
return res;
}
});
}