我不太熟悉djano是如何工作的,但是如果你想从post请求中得到响应,你需要返回
httpClient.post()
是的。请记住从rxjs包导入map。
import { tap, map } from 'rxjs/operators';
.
.
get_form_data(){
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'Basic ' + btoa('myusername:mypassword')
})
}
const request = {
"item_title": this.title,
"item_description": this.desc,
"item_price": this.price,
"item_price_later": false,
"item_action": this.action,
"item_color": this.color,
"item_category": this.category,
"item_type": this.type,
"item_size": this.size,
"item_city": this.city,
"item_phone": this.phone,
"item_image_1": "https://fostania-aws-bucket.s3.amazonaws.com/media/media/Jellyfish.jpg",
"item_image_2": null,
"item_image_3": null,
}
return this.httpClient.post('https://www.fostania.com/api/items/create/',request, httpOptions)
.pipe(
tap(data => console.log(data),
//catchError(error => console.log(error)
)}