Curl和Google Forms

4dc9hkyq  于 5个月前  发布在  Go
关注(0)|答案(1)|浏览(41)

我做的PHP脚本,将自动填充谷歌表单文档。我与 curl 做。然而,有工作的正确性这个脚本的问题

$text="forTestOnly";
if( $curl = curl_init() ){
  curl_setopt($curl,CURLOPT_URL,'SOME_URL');
  curl_setopt($curl, CURLOPT_COOKIESESSION, TRUE);
  curl_setopt($curl, CURLOPT_COOKIEFILE, "cookiefile");
  curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
  curl_setopt($curl,CURLOPT_ENCODING,'gzip,deflate');
  curl_setopt($curl,CURLOPT_USERAGENT,'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  curl_setopt($curl,CURLOPT_HEADER,true);
  if( $html = curl_exec($curl) ){
     curl_setopt($curl,CURLOPT_URL,'SOME_URL');
     curl_setopt($curl,CURLOPT_POST,TRUE);
     curl_setopt($curl,CURLOPT_POSTFIELDS,"entry.867207060=$text&submit=ok");
     $out = curl_exec($curl);
     echo $out;
  }
  curl_close($curl);
 }

字符串
它给出了这样的错误:“HTTP/1.1 405 Method Not Allowed”,这是什么问题?
对于
Link

编辑:

问题不在** curl (POST)的设置中,而是我提供的URL**不正确。

lkaoscv7

lkaoscv71#

看起来Google可能已经禁止了Google表单的POST方法,可能是为了预防自动请求。
看到
POST Request not supported by Google Server
以了解为什么会向您提供错误消息的一般解释,或者更好
cURL not fetching the expected POST response - error 405
一个可能的解决方案-看到升级的答案的建议

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query( array(...) ));

字符串
方法,该方法可能允许或不允许您绕过Google的反自动化措施。

相关问题