简体   繁体   English

Ajax发布请求获得403禁止响应

[英]Ajax Post Request gets 403 Forbidden Response

I'm using Valums file uploader ( https://github.com/Valums-File-Uploader/file-uploader ) to upload files to server. 我正在使用Valums文件上传器( https://github.com/Valums-File-Uploader/file-uploader )将文件上传到服务器。 When I try to upload file it gets uploaded 100% and then I get the 403 Forbidden response. 当我尝试上传文件时,它会上载100%,然后我收到403禁止响应。

When I access the php script which handles uploads and where script does Post request it loads normally, I don't get that 403 Forbidden error message. 当我访问处理上载的php脚本并且该脚本在哪里执行Post请求并正常加载时,我没有收到403 Forbidden错误消息。

What could be a reason for this 403 error which occurs only on post request, not on usual browser access? 仅当发布请求而不是通常的浏览器访问时发生此403错误的原因可能是什么? I tried the script on two different server setups, it worked like a charm on one, but can't get it to work on other one. 我在两个不同的服务器设置上尝试了该脚本,它在一个服务器上就像一个魅力,但无法在另一个服务器上运行。

Script for attaching file uploader to div: 用于将文件上传器附加到div的脚本:

var uploader = new qq.FileUploader({
    element: document.getElementById('file-uploader'),
    action: 'fileuploader/file_upload.php<?php if ( isset( $_GET['maxwidth'] ) ) echo "?maxwidth=" . $_GET['maxwidth']; ?>',
    params: {  },
    allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
    sizeLimit: 2097152,
    uploadButtonText: '<?php echo t('Upload image'); ?>',
    cancelButtonText: '<?php echo t('Cancel'); ?>',
    dragText: '<?php echo t('Drop files here to upload'); ?>',
    failUploadText: '<?php echo t('Upload unsuccessful'); ?>',
    onComplete: function(id, fileName, responseJSON){
        $( '#cancel-upload' ).trigger( 'click' );
        $( '#refresh' ).trigger( 'click' );
        selectFile = responseJSON['file'];
    }
}); 

file_upload.php script is slightly modified script which comes with the script: https://github.com/Valums-File-Uploader/file-uploader/blob/master/server/php.php file_upload.php脚本是该脚本附带的经过稍微修改的脚本: https : //github.com/Valums-File-Uploader/file-uploader/blob/master/server/php.php

This is response I'm receiving: 这是我收到的回复:

Request URL:http://***/mod/ckeditor/plugins/scriptemimage/php/fileuploader/file_upload.php?phpsessid=vej2rc55iajknkjsp4taecsbn2&maxwidth=600&qqfile=751152_13643298+(Custom).jpg
Request Method:POST
Status Code:403 Forbidden
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:hr,en-US;q=0.8,en;q=0.6
AlexaToolbar-ALX_NS_PH:AlexaToolbar/alxg-3.2
Connection:keep-alive
Content-Length:9774
Content-Type:image/jpeg
Cookie:__utma=***; __utmc=***; __utmz=***; PHPSESSID=***
Host:www.***.***
Origin:http://www.***.***
Referer:http://***/mod/ckeditor/plugins/scriptemimage/php/browser.php?langCode=hr&maxwidth=600&run=window.opener.document.getElementById('new-article-image').value=selectedImages();window.opener.updateThumb();
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
X-File-Name:751152_13643298%20(Custom).jpg
X-Mime-Type:image/jpeg
X-Requested-With:XMLHttpRequest
Query String Parametersview sourceview URL encoded
phpsessid:vej2rc55iajknkjsp4taecsbn2
maxwidth:600
qqfile:751152_13643298 (Custom).jpg
Response Headersview source
Connection:close
Content-Length:399
Content-Type:text/html; charset=iso-8859-1
Date:Sat, 28 Dec 2013 18:39:20 GMT
Server:Apache

This could be that your browser has cookies that authenticate it on the server, but the post request doesn't have those. 这可能是因为您的浏览器具有在服务器上对它进行身份验证的cookie,但是发布请求中没有这些cookie。 Check your browser's cookies for the upload site. 检查您的浏览器的cookie上载站点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM