POST请求标头中的内容类型缺少FormData边界 [英] FormData boundary missing from content-type in POST request header
本文介绍了POST请求标头中的内容类型缺少FormData边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的代码与在类似项目中成功使用的代码相同,但是由于某些原因,边界从未添加到请求标头的content-type属性中.这导致我的C#Web-api函数无法检测图像.
I'm using the same code as I've used successfully in a similar project for file uploads, yet for some reason the boundary never gets added to the content-type property in the request header. This results in my C# web-api function not being able to detect the image.
这是我使用angularjs发布的请求:
This is my post request using angularjs:
var formData = new FormData($('#testform')[0]);
$http({
url: serviceBase + 'api/Client/' + item.practiceID + '/SavePhoto',
method: "POST",
data: formData,
headers: { 'Content-Type': false },
transformRequest: function (data) { return data; }
}).success(function (response) {
}).error(function () {
});
这是请求的样子:
Request URL:http://localhost:56769/api/Client/178/SavePhoto
Request Headers
Provisional headers are shown
Accept:application/json, text/plain, */*
Authorization:Bearer JfDnrAIkSttZ8GnHa-Wo9wBH-HVWpbiUgGSic11DF_OlTgseuTPgTisxybvEyw2fEyer1FJ7DjKWqK15P-ZdhO_X1aHp7-GiIW2Q4BTF5svTyJKWtM2jk-XEN6qXuEIhAi6-phryd_LlGLOlLMYMKhQZGULxdyk_dUvDGt6bY5Z0L-LbV5uc74q3MyLMMj_vypNgbFCAxGEAGeeeGlP7jwlyyz7EY-eRfRhXxjFqOjI
Content-Type:false
Origin:http://localhost:58431
Referer:http://localhost:58431/index.html
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
Request Payload
------WebKitFormBoundary6padOMi9aJxqx34h
Content-Disposition: form-data; name="profile-photo"; filename="Jellyfish.jpg"
Content-Type: image/jpeg
------WebKitFormBoundary6padOMi9aJxqx34h--
有人知道在content-type参数中导致边界生成失败的原因吗?
Does anyone know what might be causing the boundary to fail to generate in the content-type parameter?
推荐答案
尝试将Content-Type
标头作为undefined
而不是false
传递:
Try passing the Content-Type
header as undefined
instead of false
:
headers: { 'Content-Type': undefined }
这篇关于POST请求标头中的内容类型缺少FormData边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文