[英]angular 5 - http post with specific header
this.headers = new Headers();
this.headers.append('Content-Type', 'multipart/form-data;boundary=--boundary');
.....
let data = new FormData();
data.append('file', file);
data.append('fileName', file.name);
data.append('fileSize', file.size.toString());
data.append('fileType', file.type);
data.append('fileLastMod', file.lastModifiedDate);
.....
let url = 'http://api.********.com/gallery/'+ this.selectedCategory;
this._http.post(url, data, {headers : this.headers})
.toPromise()
.catch(reason => {
console.log(JSON.stringify(reason));
}).then(result => {
console.log('From Promise:', result);
});
If you are sending formdata object in request then do not need to import content-type. 如果要在请求中发送formdata对象,则无需导入content-type。
Angular HTTP method support multipart type, where as HttpClient also support multipart with default reportProgress feature which will notify uploading status Angular HTTP方法支持多部分类型,其中HttpClient也支持具有默认reportProgress功能的多部分,该功能将通知上传状态
Solution- Use HTTP method, it will set boundaries on its own. 解决方案-使用HTTP方法,它将自行设置边界。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.