本文整理汇总了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)
);
}