[英]unable to send post request using angular
我正在使用HTTP post發送表單數據,就像這樣
saveDataFile(mutlidata,id,value): Observable<Response> {
var _url = 'http://xxxx.xxx.xxx';
var saveDataURL = _url + '/' + id;
var _this = this;
let headers = new Headers();
headers.append('Content-Type', 'multipart/form-data');
let options = new RequestOptions({ headers: headers });
const frmData = new FormData();
frmData.append("file",JSON.stringify(mutlidata),'sample.json');
frmData.append("dataCheck",value);
return this.http.post(saveDataURL,frmData, options).pipe(
map((res: Response) => {
return res;
}),
catchError(this.handleError),);
}
這里有多數據
[["fakepath/test1.JPG","ea305e-be9d"],["fakepath/test2.JPG","489ce580-c50e-40e6-b1ab-71c7827f636c"]]
id will have 15asdas6asd6
value will have either true / false
這里它不發送我猜的表單數據,當我調試和檢查frmdata返回this.http.post(saveDataURL,frmData,options)時,它顯示form.entries,values等
在sample.json文件中,我附加了formdata
frmData.append("file",JSON.stringify(mutlidata),'sample.json');
這里的文件意味着我必須使用該關鍵字將數據發送到API
無需附加Content-Type
,因為瀏覽器會為您處理它。 我最后一次嘗試手動將其添加到我的帖子請求時,它導致我的HTTP請求失敗。 您可以刪除部分代碼。
saveDataFile(mutlidata,id,value): Observable<Response> {
var _url = 'http://xxxx.xxx.xxx';
var saveDataURL = _url + '/' + id;
var _this = this;
const frmData = new FormData();
frmData.append("file",JSON.stringify(mutlidata),'sample.json');
frmData.append("dataCheck",value);
return this.http.post(saveDataURL, frmData, options).pipe(
map((res: Response) => {
return res;
}),
catchError(this.handleError),);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.