405不允许的方法 - 在工作一切,除了Safari浏览器iOS版 [英] 405 Method Not Allowed - Works on everything except iOS Safari

查看:1092
本文介绍了405不允许的方法 - 在工作一切,除了Safari浏览器iOS版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在AngularJS,保持一些统计数据的跟踪,并允许用户提交给谷歌的Google Apps脚本作进一步处理的应用程序。一切都完美的作品在计算机上。我已经在Chrome和Firefox中测试过,但是当我尝试提交在iPad上它显示了以下错误:

I've been trying to make an application in AngularJS that keeps track of some statistics and allows users to submit them to a google apps script for further processing. Everything works perfectly on the computer. I've tested it in chrome and in firefox, but when I try to submit on the iPad it shows the following errors:

无法加载资源:服务器与405状态响应(不允许的方法)

Failed to load resource: the server responded with a status of 405 (Method Not Allowed)

无法加载资源。不能从空作任何请求

Failed to load resource: Cannot make any requests from null.

XMLHtt prequest无法加载的https://script.googleusercontent.com/macros/echo?user_content_key=UQXGbRq6...HLV301R.无法从空作任何请求。

XMLHttpRequest cannot load https://script.googleusercontent.com/macros/echo?user_content_key=UQXGbRq6...HLV301R. Cannot make any requests from null.

var URL = 'https://script.google.com/macros/s/.../exec';

$http.post(URL,
    $.param({ packet: JSON.stringify($scope.data) }), {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
        }
    }
).success(function(data, status) {
    alert(data.packet);
    $scope.rollover();
}).error(function(data, status) {
    console.log(data);
    console.log(status);
    $scope.show_status(data);
});

它打印在控制台中一对夫妇行。数据线是空白的,返回的状态是404。

It prints a couple lines in the console. The data line is blank and the returned status is 404.

请帮帮忙!

推荐答案

请参阅<一个href=\"https://$c$c.google.com/p/google-apps-script-issues/issues/detail?can=2&start=0&num=100&q=&colspec=Stars%20Opened%20ID%20Type%20Status%20Summary%20Component%20Owner&groupby=&sort=&id=3226\" rel=\"nofollow\">https://$c$c.google.com/p/google-apps-script-issues/issues/detail?can=2&start=0&num=100&q=&colspec=Stars%20Opened%20ID%20Type%20Status%20Summary%20Component%20Owner&groupby=&sort=&id=3226

此问题仍然没有没有当前的日期设置为固定来解决。

This issue is still yet to be resolved with no current date set to be fixed.

我认为根本原因是由于谷歌应用程式不能够处理对所使用的Safari浏览器的'preflighting非标准请求到其他域OPTIONS方法脚本。

I believe the root cause is due to the google apps script not being able to handle to OPTIONS method that is used by Safari for 'preflighting' non-standard requests to other domains.

围绕我使用的工作,使我的服务器的请求,然后互动与谷歌Apps脚本。不漂亮的和缓慢的,但我需要确保网站正常工作。

The work around I am using is to make a request to my server to then interact with the google apps script. Not beautiful and slow, but I need to ensure the site is working.

下面是PHP code我曾经让我的服务器上的请求,通过在宏观,ID和板材为获得PARAMS。 PHP的然后从谷歌返回检索到的数据:

Here is the php code I used to make the request on my server, passing in the macro, id and sheet as get params. The php then returns the retrieved data from google:

<?php

header('Access-Control-Allow-Origin: *');
$url = 'https://script.google.com/macros/s/';
$url .= $_GET['macro'];
$url .= '/exec?id=';
$url .= $_GET['id'];
$url .= '&sheet=';
$url .= $_GET['sheet'];

function get_data2($url) {
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}


$response = get_data2($url);

echo $response;

?>

这现在意味着Safari浏览器正在请求同一个域,也是我们跟随403重定向注意到谷歌在我们的CURLOPT_FOLLOWLOCATION亲切的方式把。

This now means that Safari is making a request to the same domain and also we are following the 403 redirect note google kindly puts in our way with CURLOPT_FOLLOWLOCATION.

更新2015年5月7日

我注意到,虽然我收到 405方法不被允许从服务器响应,数据实际上被成功的谷歌应用程序脚本接收。例如,我已经能够没有问题接受GET和POST参数。

I've noticed that although I'm receiving a 405 method not allowed response from the server, data is actually being successfully received by the Google App Script. For example I've been able to receive the get and post parameters with no issues.

要适应这个我已经从AJAX调用的错误code实际上,我收到了错误捕捉交换机添加为 0 。 ..高兴地看到,什么是工作,但我不会在生产中信任它太多了。

To accommodate for this I've added in a switch in the error catch from the AJAX call as the error code I'm actually receiving is 0... happy to see that something is working but I wouldn't trust it too much in production.

这篇关于405不允许的方法 - 在工作一切,除了Safari浏览器iOS版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆