2

我有一个用 JavaScript 编写的测试套件,在嵌入式系统上运行的浏览器中运行。测试套件收集了大量数据,我想将其推送到服务器。我可以使用一个简单的 HttpRequest,post-method,但这需要大量的字符转义来发送内容。使用 http-file-upload 将其作为文件上传到服务器要简单得多。

有没有办法使用客户端 JavaScript 创建内存文件并使用 http-file-upload 将其推送到服务器?

由于嵌入式系统的浏览器是Ekioh,系统本身是最小的,flash、JavaApplet、SilverLight等技术不可用。只有纯 HTML5 和 JavaScript 可用。

4

1 回答 1

1

我认为一个帖子会是更好的方式来做到这一点。处理转义数据比内存文件和使用客户端 javascript 将文件推送到服务器更容易、更成熟。此外,转义数据是有原因的。您正在尝试做的是迎接许多安全漏洞。

尝试做这样的事情。摘自将 javascript 输出写入服务器上的文件的片段

var data = "...";// this is your data that you want to pass to the server (could be json)
//next you would initiate a XMLHTTPRequest as following (could be more advanced):
var url = "get_data.php";//your url to the server side file that will receive the data.
http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = function() {//Call a function when the state changes.
    if(http.readyState == 4 && http.status == 200) {
        alert(http.responseText);//check if the data was revived successfully.
    }
}
http.send(data);
于 2013-07-11T14:43:34.093 回答