【发布时间】:2020-08-19 12:00:02
【问题描述】:
我有一个调用 .NET Core API 的 Angular 单页应用程序。
默认设置会创建 HttpHeaders 以将 jwt 令牌传递给 API,并将 content-type 设置为 application/json; charset=utf-8
为了扩展这个应用程序,我一直在关注“Angular Image Upload Made Easy”(https://www.youtube.com/watch?v=YkvqLNcJz3Y),但是使用我的默认标头,API 中 FormData 中的图像始终为空。
所以我将 content-type 更改为 multipart/form-data,但得到了相同的结果。
经过大量实验,我发现根本不设置内容类型。我仍然可以通过我的 jwt 对用户进行身份验证,并且图像现在可以毫无问题地上传。
那么,在请求选项中省略 content-type 是否安全,或者插入“正确”类型会更好吗?那会是什么?
(在视频中的示例中,添加了请求选项以监控上传进度,但不包含任何标头-reportProgress:true,observe:'events')
【问题讨论】:
标签: angular .net-core http-headers content-type image-upload