本文整理匯總了TypeScript中angular2/http.Headers類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Headers類的具體用法?TypeScript Headers怎麽用?TypeScript Headers使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Headers類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: postData
postData(data){
let headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
console.log("called get req")
let httpGetPromise = new Promise((resolve, reject) => {
console.log("called get req")
this._http.post('/', data, {headers: headers})
.map(res => res.json())
.subscribe(
data => {
console.log("data from promise: ", data)
resolve(data)
},
err => reject(err),
() => console.log('data recieved')
)
})
return httpGetPromise
}
示例2: onRegister
onRegister(): void {
var data = "korisnicko_ime="+this.registerForm.value.korisnicko_ime+"&sifra="+this.registerForm.value.sifra+"&email="+this.registerForm.value.email;
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
this.http.post('http://localhost/it255/php/registracija.php',data, {headers:headers})
.map(res => res)
.subscribe( data => this.postResponse = data,
err => alert(JSON.stringify(err)),
() => {
if(this.postResponse._body == "ok"){
alert("Uspesna registracija");
this.router.parent.navigate(['./app']);
}else{
alert("Neuspesna registracija");
}
}
);
}
示例3: login
login(user: User) {
var headers = new Headers();
headers.append("Content-Type", "application/json");
return this._http.post(
Config.apiUrl + "oauth/token",
JSON.stringify({
username: user.email,
password: user.password,
grant_type: "password"
}),
{ headers: headers }
)
.map(response => response.json())
.do(data => {
Config.token = data.Result.access_token;
})
.catch(this.handleErrors);
}
示例4: onAddRoom
onAddRoom(): void {
var data = "newRoomName="+this.signupForm.value.newRoomName+"&tv="+this.signupForm.value.tv+"&beds="+this.signupForm.value.beds+"&kvadratura="+this.signupForm.value.kvadratura;
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
this.http.post('http://localhost/php/addroom.php',data, {headers:headers})
.map(res => res)
.subscribe( data => this.postResponse = data,
err => alert(JSON.stringify(err)),
() => {
if(this.postResponse._body.indexOf("error") === -1){
alert("Uspesno dodavanje sobe");
this.router.parent.navigate(['./Home']);
}else{
alert("Neuspesno dodavanje sobe");
}
}
);
}
示例5: signin
signin(username:string, password:string) {
var creds = "username=" + username + "&password=" + password;
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
this.http.post('http://localhost:8080/account/token', creds, {
headers: headers
})
.map(res => res.json())
.subscribe(
data => {
this.saveJwt(data.access_token);
this._router.navigate(['Dashboard']);
},
err => console.error(err),
() => console.log('Authentication Complete')
);
}
示例6: sendNotification
public sendNotification(RestaurantEmail:string, TableNr:string) {
let parameters = JSON.stringify({
restaurant: RestaurantEmail,
tableNr: TableNr
});
let header:Headers = new Headers();
header.append('Content-Type', 'application/json');
header.append('AnonymousToken', ConfigBackand.anonymous_token);
return this.http.get(ConfigBackand.api_url + '1/objects/action/Order/?name=SendRealtimeEvent¶meters=' + encodeURI(parameters), {headers: header})
.map(res => res.json())
}
示例7: getTables
public getTables(restaurantId) {
if (restaurantId != null || restaurantId != "") {
let filter = JSON.stringify([{"fieldName": "RestaurantId", "operator": "equals", "value": restaurantId}]);
let header:Headers = new Headers();
header.append('AnonymousToken', ConfigBackand.anonymous_token);
return this.http.get(ConfigBackand.api_url + '1/objects/Tables?filter=' + encodeURI(filter), {
headers: header
})
.retry(3)
.map(res => res.json().data.map(r => r))
}
else {
}
}
示例8: Courses_GetCourses
/**
*
* @method
* @name Courses_GetCourses
* @param {string} q -
*
*/
public Courses_GetCourses(q: string) {
let payload = {};
let queryParameters = new URLSearchParams();
let headers = new Headers();
headers.append('Content-Type', 'application/json');
if(q !== undefined){
queryParameters.set('q', q);
}
let uri = `/api/courses`;
return this.http
.get(this.domain + uri, { headers: headers, search: queryParameters })
.map((res: Response) => {
return res;
});
}
示例9: save
save() {
var headers = new Headers();
headers.append('Content-Type', 'application/json');
var _this = this;
this.loading = true;
var json = JSON.stringify(this.catToEdit);
console.log(json);
_this._http.post('/api/Category', json,
{ headers: headers }).map(r => r.json()).subscribe(x => {
_this.loading = true;
_this.load();
},
error => {
_this._errorHandler.handleError(error);
_this.loading = false;
});
}
示例10: login
public login(user: User): Observable<Response>{
var headers = new Headers();
headers.append('Content-Type', 'application/json');
return this._http.post(
Config.apiUrl + 'oauth/token',
JSON.stringify({
username: user.email,
password: user.password,
grant_type: 'password'
}),
{ headers: headers }
)
.map(response => response.json())
.do(data => {
Config.token = data.Result.access_token;
})
.catch(this.handleErrors);
}