如何解决问题-用CURL将数据发送到脚本


How to trouble shoot - post data to script with 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,$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); ?>

我的帖子变量字符串看起来像这样:

surname=smth&address1=No+Value&this=that

我得到的结果是:

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

你可以试试:

<>之前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上重定向。