Curl and Google Forms


Curl and Google Forms

我正在制作PHP脚本,将自动填充谷歌表单文档。我和柯尔在一起了。然而,在此脚本

工作的正确性方面存在问题。
$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"。有什么问题吗?

链接


编辑:

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

看来Google可能已经禁止了Google表单的POST方法,可能是为了预防,呃,自动请求。

Google Server不支持POST请求

给出给出错误信息的一般解释,或者

cURL未获取预期的POST响应-错误405

为一个可能的解决方案-请参阅升级的答案的建议

 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query( array(...) ));
方法,该方法可能允许也可能不允许您绕过谷歌的反自动化措施。