我想使用 plupload 库将文件上传到远程服务器。使用 html5 运行时的 Chrome (32.0) 和 IE 10 一切正常,但当我尝试使用 Firefox 27(html5 运行时)或 IE 8(html4 运行时)时,出现错误Error #-200: HTTP Error.
.
客户端脚本:
$(function() {
var uploader = new plupload.Uploader({
browse_button: 'browse',
url: 'https://remote.com/API/action.php',
runtimes : 'html5,flash,silverlight,html4',
flash_swf_url : './js/Moxie.swf',
silverlight_xap_url : './js/Moxie.xap'
});
uploader.init();
uploader.settings.multipart_params = {
[...]
};
// PreInit events, bound before any internal events
uploader.bind('init', function(up, info) {
console.log('[Init]', 'Info:', info, 'Features:', up.features);
alert(info['runtime']);
});
uploader.bind('Error', function(up, err) {
document.getElementById('console').innerHTML += "\nError #" + err.code + ": " + err.message;
});
document.getElementById('start-upload').onclick = function() {
uploader.start();
};
});
Chrome 的第一个请求:
Request URL:https://remote.com/API/action.php
Request Method:OPTIONS
Status Code:200 OK
Chrome 的第二个请求:
Request URL:https://remote.com/API/action.php
Request Method:POST
Status Code:200 OK
请求标头
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Access-Control-Request-Headers:content-type
Access-Control-Request-Method:POST
Cache-Control:no-cache
Connection:keep-alive
Host:hipt.ucc.ie
Origin:http://server.com
Pragma:no-cache
Referer: XXX
User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36
响应头
Access-Control-Allow-Headers:Content-Type, Authorization, X-Requested-With
Access-Control-Allow-Methods:GET, PUT, POST, DELETE, OPTIONS
Access-Control-Allow-Origin:*
Access-Control-Max-Age:1000
Cache-Control:no-cache
Connection:close
Content-Length:5
Content-Type:text/html; charset=UTF-8
Date:Mon, 24 Feb 2014 11:57:54 GMT
Server:Apache/2.2.3 (CentOS)
X-Powered-By:PHP/5.1.6
服务器端脚本:
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Cache-Control: no-cache');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
if (!empty($_FILES)) {
对于 Firefox,对请求的响应是OPTIONS
方法为空并且没有以下内容POST
要求。
以下是 Firefox 的标头:
我不明白为什么它不能在 Firefox 和 IE8 上运行。
感谢您的帮助。
[编辑] 我刚刚尝试过 flash 运行时:它适用于 Chrome 和 IE 10,但不适用于 Firefox 和 IE8。奇怪的是,alert(info['runtime']);
没有出现,但控制台中没有 javascript 错误...