我试图通过xmlhttprequest或jquery ajax通过跨服务器发送一个文件,这两个似乎都将文件发送到我的开发服务器,在那里我有一个php来将比特流保存为docx格式。
问题是,当我把它发送到我的客户端服务器时,它们得到的是0字节。奇怪的是。当我使用postman发送文件时,它工作得很好。下面是我读取和发送文件的代码。
var xhr = new XMLHttpRequest();
xhr.open('GET', my_file, true);
xhr.setRequestHeader("cache-control", "no-cache");
xhr.responseType = 'blob';
xhr.onload = function(e) {
if (this.status == 200) {
// get binary data as a response
var blob = this.response;
var resume = new XMLHttpRequest();
resume.open('POST', client_api, true);
resume.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
resume.send(blob);
}
};
xhr.send();
我还能够获取发送到我的服务器的数据。我的客户的开发人员说我需要在POST主体中发送数据流...在这一点上我完全迷惑了。
请帮帮忙。提前谢谢。
发布于 2016-09-24 15:55:57
https://stackoverflow.com/questions/39673909
复制相似问题