简体   繁体   English

角度5-具有特定标题的http帖子

[英]angular 5 - http post with specific header

My headers are set in constructor as follow: 我的标头在构造函数中设置如下:

this.headers = new Headers();
this.headers.append('Content-Type', 'multipart/form-data;boundary=--boundary');

I have collected data to post it out in formData 我已经收集了数据以将其发布到formData中

            .....
 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);
            .....

Here i am posting the data 我在这里发布数据

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);
            });

But i get following error: 但我得到以下错误:

在此处输入图片说明

API that i am approaching requires following: 我正在处理的API需要满足以下条件:

在此处输入图片说明


So my question is how to set up these requirements like boundaries, content disposition an so on ? 所以我的问题是如何设置这些要求,如边界,内容配置等? These are pretty new things to me. 对我来说,这些都是新事物。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM