PHP cURL不';t不允许我设置POST请求,它设置了';让我们取而代之
所以getinfo告诉我: 获取HTTP/1.1 而不是 POST HTTP/1.1 这不是代理错误-我在没有代理的情况下尝试过-结果相同PHP cURL不';t不允许我设置POST请求,它设置了';让我们取而代之,php,curl,Php,Curl,所以getinfo告诉我: 获取HTTP/1.1 而不是 POST HTTP/1.1 这不是代理错误-我在没有代理的情况下尝试过-结果相同 那么为什么卷曲力会变大呢?而不是执行正常的POST请求?发生这种情况的原因是您设置了CURLOPT\u FOLLOWLOCATION cURL实际上并没有执行GET请求而不是POST,它也在这样做。这是因为您发布到的URL使用该模式,许多HTTP驱动的应用程序都使用该模式。它基本上是一种机制,用于帮助确保用户不会意外地执行一个操作两次(简而言之,它比实际情况
那么为什么卷曲力会变大呢?而不是执行正常的POST请求?发生这种情况的原因是您设置了
CURLOPT\u FOLLOWLOCATION
cURL实际上并没有执行GET请求而不是POST,它也在这样做。这是因为您发布到的URL使用该模式,许多HTTP驱动的应用程序都使用该模式。它基本上是一种机制,用于帮助确保用户不会意外地执行一个操作两次(简而言之,它比实际情况稍微复杂)
将数据发布到服务器时,服务器会处理请求并发出重定向,以便返回相关内容,而不是简单地在对POST请求的响应中返回
总之,你实际上没有问题。让代码保持原样,只要请求数据正确,远程服务器上的结果将是您期望的结果。我假设
curl\u setopt()
不介意您使用整数而不是布尔值?这没有任何区别。@user1652792您可以删除curl\u setopt($this->curl,CURLOPT\u HTTPGET,0)代码>行?这应该是多余的,我想知道这是否与此有关。哦,等等,等等。删除CURLOPT\u FOLLOWLOCATION
行,看看会发生什么。真的吗?在我看来,该网站正在向您发送302/303响应,因为它使用PRG,并且因为您设置了CURLOPT_FOLLOWLOCATION
set,它只会向您显示最新的请求,即重定向的GET。
$this->curl = curl_init();
curl_setopt($this->curl, CURLOPT_URL, 'http://something.com/send');
curl_setopt($this->curl, CURLOPT_REFERER, 'http://something.com');
curl_setopt($this->curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1');
curl_setopt($this->curl, CURLOPT_ENCODING, 'gzip, deflate');
curl_setopt($this->curl, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/cookies.txt');
curl_setopt($this->curl, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookies.txt');
curl_setopt($this->curl, CURLOPT_HTTPGET, 0);
curl_setopt($this->curl, CURLOPT_POST, 1);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, 'name=john');
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
@curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($this->curl, CURLOPT_HTTPPROXYTUNNEL, FALSE);
curl_setopt($this->curl, CURLOPT_PROXY, $this->proxy['0']);
curl_setopt($this->curl, CURLOPT_PROXYPORT, $this->proxy['1']);
curl_setopt($this->curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($this->curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
curl_setopt($this->curl, CURLOPT_PROXYUSERPWD, $this->proxy['2'] . ':' . $this->proxy['3']);
curl_setopt($this->curl, CURLOPT_HEADER, 1);
curl_setopt($this->curl, CURLINFO_HEADER_OUT, 1);
curl_setopt($this->curl, CURLOPT_VERBOSE, 1);$this->website = curl_exec($this->curl);
var_dump(curl_getinfo($this->curl));
var_dump(curl_error($this->curl));
echo $this->website;