我在我的网站上使用 jQuery jPlayer 圆形皮肤来播放远程 url,以下代码工作得很好,除非 url 来自特定域(称之为http://prob.lem),我总是得到"NetworkError: 403 Forbidden - http://prob.lem/upload_music/7154816.mp3"
,虽然我使用浏览器或使用 wget 下载 mp3 都没有问题。我对 jQuery 的了解有限,我最好的猜测是 jQuery jPlayer 发送请求的方式与通常的浏览器或 wget 不同(错误?),另一个检测到它并拒绝提供内容。
问题是:假设我猜对了,我的网站是否有解决办法让我的 jPlayer 仍然可以获取内容?如果我的猜测是错误的,我还应该去哪里看?谢谢,
<script type="text/javascript">
//<![CDATA[
var $j = jQuery.noConflict();
$j(document).ready(function(){
var myCirclePlayer = new CirclePlayer("#jquery_jplayer_1",
{
mp3: "http://prob.lem/upload_music/7154816.mp3"
}, {
cssSelectorAncestor: "#cp_container_1",
supplied: "mp3",
swfPath: "wp-content/plugins/magic-media-box/js/Jplayer.swf",
wmode: "window",
keyEnabled: true,
});
});
//]]>
</script>
此外,以下是来自 firebug 的请求信息:
Response Headers
HTTP/1.1 403 Forbidden
Date: Tue, 23 Jul 2013 20:24:25 GMT
Server: Apache
Content-Length: 291
Connection: close
Content-Type: text/html; charset=iso-8859-1
Request Headers
GET /upload_music/7154816.mp3 HTTP/1.1
Host: prob.lem
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0
Accept: audio/webm,audio/ogg,audio/wav,audio/*;q=0.9,application/ogg;q=0.7,video/*;q=0.6,*/*;q=0.5
Accept-Language: en-US,en;q=0.5
Range: bytes=0-
Referer: http://my.site/index.php/category/ktv/
Connection: keep-alive
如果我直接在 Firefox 中打开链接,请求信息看起来确实不同:
Response Headers
HTTP/1.1 200 OK
Date: Tue, 23 Jul 2013 20:34:12 GMT
Server: Apache
Last-Modified: Sun, 21 Jul 2013 23:05:06 GMT
Etag: "1b2803e-b5ffef-4e20d97386aba"
Accept-Ranges: bytes
Content-Length: 11927535
Connection: close
Content-Type: audio/mpeg
Request Headers
GET /upload_music/7154816.mp3 HTTP/1.1
Host: prob.lem
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
我可以看到,在请求标头中,Accept
和Accept-Encoding
字符串不同,因此响应也不同。我可以让 jQuery jPlayer 发送与 Firefox 浏览器相同的标题吗?
谢谢,