![](/img/trans.png)
[英]$http request is passed to the server in angular js without specify it on the client side
[英]Http request is different between client and server
在客戶端,我用$ http發送請求:
Upload.upload({
url: 'http://localhost:3000/upload',
fields: {
'username': $scope.username
},
file: file
})
在服務器端,這是路由:
app.route('/upload')
.get(function (req) {
for (var key in req)
console.log(key);
})
但是我在req中看不到任何密鑰名稱文件嗎? 兩者之間存在這種差異的原因是什么?
您需要添加標頭以使用post上傳文件,需要進行multipart / form-data請求,
var fd = new FormData();
fd.append("file", file);
$http.post(uploadUrl, fd, {
withCredentials: true,
headers: {'Content-Type': undefined },
transformRequest: angular.identity
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.