XmlHttpRequest跨域[重复](XmlHttpRequest cross-domain [duplicate])
这个问题在这里已有答案:
- 如何规避同源政策 11答案
我试图向远程Rest(put方法)api发出请求
var xhReq = new XMLHttpRequest(); xhReq.open("PUT", "http://api-easybib.apigee.com/2.0/rest/cite", true); xhReq.setRequestHeader('Content-Type', 'application/json'); var jsonString = "{...}"; xhReq.send(JSON.stringify(jsonString)); var serverResponse = xhReq.responseText;
它失败了
没有'Access-Control-Allow-Origin'标题
虽然我成功通过休息客户端浏览器插件拨打电话 。
我错过了什么?
This question already has an answer here:
- Ways to circumvent the same-origin policy 11 answers
Im trying to make requests to a remote Rest (put method) api
var xhReq = new XMLHttpRequest(); xhReq.open("PUT", "http://api-easybib.apigee.com/2.0/rest/cite", true); xhReq.setRequestHeader('Content-Type', 'application/json'); var jsonString = "{...}"; xhReq.send(JSON.stringify(jsonString)); var serverResponse = xhReq.responseText;
it fails with
No 'Access-Control-Allow-Origin' header
although i succeeded to make call via rest client browser plugins.
What am i missing?
原文:https://stackoverflow.com/questions/21855064
更新时间:2021-07-28 14:07
最满意答案
$config['allowed_type']
应该是一个mime类型列表,但它恰好发生,有时候只是文件扩展名会起作用(至少对于图像来说是这种情况)。
尝试:
$config['allowed_type'] = 'application/zip';
虽然这些也是zip的MIME类型:
application/x-zip application/x-zip-compressed application/octet-stream application/x-compress application/x-compressed multipart/x-zip
I solved it using the code provided by "kofic" here: http://ellislab.com/forums/viewthread/113029/
相关问答
更多-
如果有帮助,请使用它 function do_upload($act_id) { $file_ary = $this->reArrayFiles($_FILES['add_file']); $allowed = array('png', 'jpg', 'gif','jpeg','gif','zip','docx','pdf','txt'); $gal = "../public/assets/ ...
-
如果您使用的是版本2.1.0,则上载库中存在错误。 请参阅以下链接,此处将对此进行清楚说明。 在Codeigniter中上传 - 不允许您尝试上传的文件类型 If you are using version 2.1.0, there is a bug in the upload library. Refer the below link, it is explained clearly here. Uploading in Codeigniter - The filetype you are attempt ...
-
为此使用角度文件上传从这里下载: https://github.com/nervgh/angular-file-upload 使用此控制器: app.controller('FileUploadCtrl', ['$scope', 'FileUploader', function($scope, FileUploader) { var uploader = $scope.uploader = new FileUploader({ url: 'Your Api path', ...
-
尝试使用以下行在该文件夹中创建.htaccess文件: Deny from all 如果需要下载文件,请创建一个控制器并使用下载帮助程序(force_download函数)。 这将禁用所有类型的访问(因此您不能在网站中使用此文件,如果它们是您无法使用它们的图像)。 Try creating a .htaccess file in that folder, with the following line: Deny from all If you need to download the file, cr ...
-
Codeigniter上传文件问题(Codeigniter Upload File Issue)[2022-04-06]
只需在do_upload()函数中传递HTML字段名称属性:参见下面的代码: $ this-> upload-> do_upload(' userfile '); 我希望它能奏效。 Just pass the HTML field name attribute in do_upload() function: See below code: $this->upload->do_upload('userfile'); I hope it will work. -
这段代码很适合我,你需要在控制器上管理它。 不要忘记添加jquery.form.min.js。