Php 如何排除故障-使用CURL将数据发布到脚本

Php 如何排除故障-使用CURL将数据发布到脚本,php,post,curl,Php,Post,Curl,我需要将一些数据发布到服务器上的脚本中。我正在使用curl和详细的错误报告。有人知道为什么这不起作用吗 谢谢 发帖脚本 function makePost($postvars, $count) { $url = 'http://servername.something.org/php/callback-f.php'; $ch = curl_init(); curl_setopt ($ch, CURLOPT_POST, true); curl_setopt($ch,CURLOPT_URL,$

我需要将一些数据发布到服务器上的脚本中。我正在使用curl和详细的错误报告。有人知道为什么这不起作用吗

谢谢

发帖脚本

function makePost($postvars, $count) {

$url = 'http://servername.something.org/php/callback-f.php';

$ch = curl_init();

curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars);
curl_setopt($ch, CURLOPT_VERBOSE, 1);

$result = curl_exec($ch);
curl_close($ch);
}
发布到的脚本包含以下行:

<?php log_error("success",ERROR_LOG_TO_STDERR); ?>
我得到的结果是:

Connected to myserver.org port 80
> POST /php/callback-f.php HTTP/1.1
Host: myserver.org
Pragma: no-cache
Accept: */*
Content-Length: 1510
Content-Type: application/x-www-form-urlencoded

< HTTP/1.1 301 Moved Permanently
< Location: https://myserver/php/callback-f.php
< Content-Length: 0
< Date: Wed, 16 Nov 2011 16:21:23 GMT
< Server: lighttpd/1.4.28
* Connection #0 to host left intact
* Closing connection #0
已连接到myserver.org端口80
>POST/php/callback-f.php HTTP/1.1
主持人:myserver.org
Pragma:没有缓存
接受:*/*
内容长度:1510
内容类型:application/x-www-form-urlencoded
您是否可以尝试使用:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
您将返回一个301错误。您尝试的url是
http://servername.something.org
而301则表示该页面位于
https://myserver
(注意https协议)


301错误也不应在未经用户同意的情况下在POST上重定向。

看起来您的测试脚本只能通过https访问,但您是通过http发布的。您好,感谢您的快速回答。不幸的是,这不起作用。我得到了以下错误:嗯,现在的问题是:SSL:certificate subject name“Common name(例如,YOUR name)”与目标主机名“myservername.org”51 curl_setopt($ch,CURLOPT_POST,true)不匹配;52 curl_setopt($ch,CURLOPT_URL,$URL);53 curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);54 curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars);55 curl_setopt($ch,CURLOPT_VERBOSE,1);56 curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);57 curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);58 curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);好的,我知道问题是这个301重定向-谢谢你的帮助!现在剩下的就是:*违反RFC2616/10.3.2,从POST切换到GET Curl,在重定向时切换到GET。有没有办法阻止这种情况发生? curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);