此URL php错误不支持HTTP方法POST

此URL php错误不支持HTTP方法POST,php,http,post,Php,Http,Post,我试图用以下代码编辑和显示google fusion表中的数据: <?php include('Lib/clientlogin.php'); include('Lib/sql.php'); include('Lib/file.php'); //get token $token = ClientLogin::getAuthToken('usernane', 'password'); $ftclient = new FTClientLogin($token); //show all ta

我试图用以下代码编辑和显示google fusion表中的数据:

<?php

include('Lib/clientlogin.php');
include('Lib/sql.php');
include('Lib/file.php');

//get token
$token = ClientLogin::getAuthToken('usernane', 'password');
$ftclient = new FTClientLogin($token);

//show all tables
echo $ftclient->query(SQLBuilder::showTables());
echo "<br />";

//describe a table
echo $ftclient->query(SQLBuilder::describeTable(2683865));
echo "<br />";

//select * from table
echo $ftclient->query(SQLBuilder::select(2683865));
echo "<br />";

//select * from table where test=1
echo $ftclient->query(SQLBuilder::select(2683865, null, "'test'=1"));
echo "<br />";

//select test from table where test = 1
echo $ftclient->query(SQLBuilder::select(2683865, array('test'), "'test'=1"));
echo "<br />";

//select rowid from table
echo $ftclient->query(SQLBuilder::select(2683865, array('rowid')));
echo "<br />";

//delete row 401
echo $ftclient->query(SQLBuilder::delete(2683865, '401'));
echo "<br />";

//drop table
echo $ftclient->query(SQLBuilder::dropTable(358731));
echo "<br />";

//update table test=1 where rowid=1
echo $ftclient->query(SQLBuilder::update(2683865, array('test'=>12), 1));
echo "<br />";

//insert into table (test, test2, 'another test') values (12, 3.3333, 'bob')
echo $ftclient->query(SQLBuilder::insert(2683865, array('test'=>12, 'test2' => 3.33333, 'another test' => 'bob')));

?>
Hide details
Change log
r8 by kbris...@google.com on Apr 7, 2011   Diff
updates to library
Go to:  
Older revisions
 r4 by kbris...@google.com on Dec 17, 2010   Diff 
 r3 by kbris...@google.com on Dec 17, 2010   Diff 
All revisions of this file
File info
Size: 1321 bytes, 50 lines
View raw file
我以前在这台服务器上使用过php“POST”命令,没有任何问题。如果任何人对可能出现的问题有任何想法,我们将感谢您的帮助

编辑:下面是query()函数的代码。我相信这就是错误的根源:

function query($query, $gsessionid = null, $recursedOnce = false) {

    $url = SCOPE;
        $query =  "sql=".urlencode($query);

    $fusiontables_curl=curl_init();
    if(preg_match("/^select|^show tables|^describe/i", $query)) { 
          $url .= "?".$query;
      if($gsessionid) { $url .= "&gsessionid=$gsessionid"; }
      curl_setopt($fusiontables_curl,CURLOPT_HTTPHEADER, array("Authorization: GoogleLogin auth=".$this->token));

    } else {
      if($gsessionid) { $url .= "?gsessionid=$gsessionid"; }

      //set header
      curl_setopt($fusiontables_curl,CURLOPT_HTTPHEADER, array( 
        "Content-length: " . strlen($query), 
        "Content-type: application/x-www-form-urlencoded", 
        "Authorization: GoogleLogin auth=".$this->token         
      )); 

      //set post = true and add query to postfield
      curl_setopt($fusiontables_curl,CURLOPT_POST, true);
      curl_setopt($fusiontables_curl,CURLOPT_POSTFIELDS,$query); 
    }

    curl_setopt($fusiontables_curl,CURLOPT_URL,$url);
    curl_setopt($fusiontables_curl,CURLOPT_CONNECTTIMEOUT,2);
    curl_setopt($fusiontables_curl,CURLOPT_RETURNTRANSFER,1);
    $result = curl_exec($fusiontables_curl);
    curl_close($fusiontables_curl);

    //If the result contains moved Temporarily, retry
    if (strpos($result, '302 Moved Temporarily') !== false) {
      preg_match("/(gsessionid=)([\w|-]+)/", $result, $matches);

      if (!$matches[2]) { return false; }

      if ($recursedOnce === false) {
        return $this->query($url, $matches[2], true);
      }
      return false;
    }

    return $result;
  }

我不确定你的服务器是否有问题。该错误表示该URL不支持POST。我知道谷歌对POST命令很敏感,如果你试图在普通搜索中从GET切换到POST,你的搜索就会被拒绝。在这种情况下可能也是这样

尝试使用GET或check调用POST命令,我在代码中没有看到它

编辑:

发件人:

API语句使用HTTP GET请求(用于查询)和POST请求(用于插入、更新和删除)从Web客户端应用程序发送到Google Fusion Tables服务器


正如我所建议的,您可以使用GET来检索数据,使用POST-only发送命令来编辑数据。将query()函数更改为使用GET,然后编写一个单独的edit()函数,使用POST编辑数据

看不到发送
POST
请求的代码,也看不到您正在呼叫的地址。请扩展您的问题。谢谢您的回复。我已经将我认为存在问题的发布功能包含在上述修订代码中。如果你知道我错了什么,我会很感激的!谢谢你的回复。我已经在上面的代码中包含了query()函数的代码。我相信这就是错误产生的原因。如有任何建议,将不胜感激。
function query($query, $gsessionid = null, $recursedOnce = false) {

    $url = SCOPE;
        $query =  "sql=".urlencode($query);

    $fusiontables_curl=curl_init();
    if(preg_match("/^select|^show tables|^describe/i", $query)) { 
          $url .= "?".$query;
      if($gsessionid) { $url .= "&gsessionid=$gsessionid"; }
      curl_setopt($fusiontables_curl,CURLOPT_HTTPHEADER, array("Authorization: GoogleLogin auth=".$this->token));

    } else {
      if($gsessionid) { $url .= "?gsessionid=$gsessionid"; }

      //set header
      curl_setopt($fusiontables_curl,CURLOPT_HTTPHEADER, array( 
        "Content-length: " . strlen($query), 
        "Content-type: application/x-www-form-urlencoded", 
        "Authorization: GoogleLogin auth=".$this->token         
      )); 

      //set post = true and add query to postfield
      curl_setopt($fusiontables_curl,CURLOPT_POST, true);
      curl_setopt($fusiontables_curl,CURLOPT_POSTFIELDS,$query); 
    }

    curl_setopt($fusiontables_curl,CURLOPT_URL,$url);
    curl_setopt($fusiontables_curl,CURLOPT_CONNECTTIMEOUT,2);
    curl_setopt($fusiontables_curl,CURLOPT_RETURNTRANSFER,1);
    $result = curl_exec($fusiontables_curl);
    curl_close($fusiontables_curl);

    //If the result contains moved Temporarily, retry
    if (strpos($result, '302 Moved Temporarily') !== false) {
      preg_match("/(gsessionid=)([\w|-]+)/", $result, $matches);

      if (!$matches[2]) { return false; }

      if ($recursedOnce === false) {
        return $this->query($url, $matches[2], true);
      }
      return false;
    }

    return $result;
  }