本文整理匯總了TypeScript中angular2/http.Http.post方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Http.post方法的具體用法?TypeScript Http.post怎麽用?TypeScript Http.post使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類angular2/http.Http
的用法示例。
在下文中一共展示了Http.post方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: post
post(request) {
//console.log(request)
let body = JSON.stringify(request.data);
let headers = this.buildHeaders([
{ key: 'Content-Type', value: 'application/json' },
{ key: 'Accept', value: 'application/json' }
]);
let options = new RequestOptions({ headers: headers });
return this.http.post(request.url, body, options);
}
示例2: addRole
addRole(role) {
var headers = new Headers();
headers.append('Content-Type', 'application/json');
return this._http.post(this._config.apiEndpoint + '/role', JSON.stringify(role), { // All hosts to config.
headers: new Headers({
'Authorization': 'Bearer ' + this._auth.getToken(),
'Content-Type': 'application/json'
})
}).map((res) => {
let doc = res.json();
let roles = doc;
return roles;
});
}
示例3: Headers
.flatMap( (saga)=>{
console.log('init post ',saga);
var t=localStorage.getItem('token');
if (t==null) return Observable.of(null);
var h:Headers=new Headers();
h.append('Authorization',t);
const query=http.post('http://virtual2.ballistix.co.uk:8000/api/maintenance',JSON.stringify({type:''}),{headers:h});
return query.map((e)=>e.json()).catch((e)=>{return Observable.of(null)});
})
示例4: putAlumno
// PUT
public putAlumno(alumno: Alumno) {
var obj = {
'__metadata': { 'type': 'SP.Data.AlumnoListItem' },
'Nombre': alumno.nombre,
'Apellidos': alumno.apellidos,
'Puntuacion': alumno.puntuacion,
'Guid': alumno.userGuid,
'AccountName': alumno.accountName
};
var data = JSON.stringify(obj);
return this.http.post(this.spApiUrl + "/_api/web/lists/getByTitle('Alumno')/items(" + alumno.id + ")", data, { headers: this.setHeaders("PUT") });
}
示例5: return
let result = Observable.create((observable) => {
this._http.post(this.getSaveEndpoint(obj.id), JSON.stringify(obj))
.map(res => res.json())
.map((instance: any) => {
if (instance) {
return (this.fromJson(instance));
}
return null;
}).subscribe(
(data) => observable.next(data),
(err) => observable.error(err),
() => observable.complete()
);
});
示例6: addPerson
addPerson(name: string) {
var data = {
Name: name
};
var headers = new Headers();
headers.append('Content-Type', 'application/json');
return this._http.post(
'http://localhost:51523/api/home',
JSON.stringify(data), {
headers: headers
});
}
示例7: login
login (username: string, password: string, profile: number): Observable<string> {
var loginData = [username, password, profile];
let body = JSON.stringify(loginData);
//let body = [username, password, profile];
console.log("RequestBody = " + body);
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post(BackEndURL + '/login', body, options)
.map(this.extractData)
.catch(this.handleError);
}
示例8: Promise
return new Promise(resolve => {
this.http.post(url, datatobepost, {
headers: headers
})
.map(res => res.json())
.subscribe(
data => {
resolve(data);
},
err => {
resolve('Error');
}
);
});
示例9: addJSON
addJSON(url: string, obj: any, cb: ServerResponse): void {
let headers: Headers = new Headers();
headers.append('Content-Type', 'application/json');
let options: RequestOptions = new RequestOptions();
options.headers = headers;
this.http.post(url, JSON.stringify(obj), options)
.subscribe((res: Response) => {
cb(res.json()); //callBack
}); //http.post
} //addJSON
示例10: anadirJugador
anadirJugador(nombre:string, posicion:string, kda:number, equipo:number){
let url = "https://localhost:8443/jugadores/";
let item = { "nombre":nombre, "posicion":posicion, "media":kda, "equipo":{"id": equipo}
};
let body = JSON.stringify(item);
let headers = new Headers({
'Content-Type': 'application/json'
});
let options = new RequestOptions({ headers });
return this.http.post(url, body, options)
.map(response => response.json())
.catch(error => this.manejarError(error)
);
}