使用方法Post AngularJs时出错
有人可以修复它,当我使用邮递员我的restfull是好的,但不是从我的客户端使用方法Post AngularJs时出错,angularjs,postman,Angularjs,Postman,有人可以修复它,当我使用邮递员我的restfull是好的,但不是从我的客户端 var req = { method: 'POST', url: 'http://localhost:8098/getfiles', headers: { 'Content-Type': 'multipart/form-data', }, data: { 'selectedFiles': 'D:\\quadtech
var req = {
method: 'POST',
url: 'http://localhost:8098/getfiles',
headers: {
'Content-Type': 'multipart/form-data',
},
data: { 'selectedFiles': 'D:\\quadtech\\Intellegent\\AppSpringBoot\\input\\bismillah.txt' }
}
return $http(req).then(function(response){console.log(response); return response;}, function(){});
我的控制台中的错误是
POST http://localhost:8098/getfiles 500 ()
这是邮递员的要求
使用formData而不是data发送:
var req = {
method: 'POST',
url: 'http://localhost:8098/getfiles',
headers: {
'Content-Type': 'multipart/form-data',
},
formData: {
'selectedFiles': fs.createReadStream('D:\\quadtech\\Intellegent\\AppSpringBoot\\input\\bismillah.txt') }
}
return $http(req).then(function(response){console.log(response); return response;}, function(){});
请参阅文档:您的服务器需要表单数据。您正在发送JSON。如果您在浏览器开发工具的“网络”面板中查看发送的请求,这一点就显而易见了。使用正确的内容类型,以正确的格式发送数据。'content-type':'multipart/form data'使用此选项时出现错误500