code as below.
let myHeader = new Headers();
//myHeader.append("Authorization", "Bearer " + localStorage.getItem("token"));
myHeader.append('content-type', 'multipart/form-data; boundary=-------------------------acebdf13572468');
this.http.post(url, formData, { headers: myHeader }).subscribe(result => {
this.model = result.json() as ResourceFile;
});
at server end, I alway got "content-type" header = "application/json". but I switched to Http module in @angular/http, it works.
Do you have any global headers set in your AuthConfig?
let headers = new Headers();
let options = new RequestOptions({ headers: headers });
this.http.post(url, formData, options)
this may be helpful friend.,
@vigneshpr thanks! but it doesn't work. this.http is AuthHttp, and there is no parameters like that. please try it yourself if you are interesting in it.
AuthHttp should match http's API. You can definitely pass an options object and we'll append our headers. Can you address @chenkie's question? If you're not setting globabl headers, this should work.
check your global headers in main module, maybe u got wrong config
gobalHeaders: [{ 'Content-Type': 'application/json' }]
delete this
I can confirm that deleting the global headers solved my very similar problem where AuthHttp was dumping my form data after I appended a few strings and a file to it. This was the last thing I checked because I've been using global headers for a long time now.
Agree that it works, if we delete global headers. But if we pass optional parameters it should override global headers, isn't it?
Can you overide gobalHeaders in some way?
I'm here for the same issue - needed to override the default headers for one instance.
However, I found that not setting default headers seems to work perfectly fine, and I that I don't seem to need to specify headers at all. 🤷♂️
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇♂️
Most helpful comment
Agree that it works, if we delete global headers. But if we pass optional parameters it should override global headers, isn't it?