2011-11-16 22 views
0

我需要将一些数据发布到我的服务器上的脚本。我正在使用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); ?> 

我的POST变量一个字符串,它看起来像这样:

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 
+1

看起来您的测试脚本只能通过https访问,但您通过http发布。 – liquorvicar

回答

1

你能尝试使用:

 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
+0

嗨,谢谢你的快速回答。不幸的是,这是行不通的。我得到以下错误: – rix

+0

hmmm,问题现在是这样的:SSL:证书使用者名称'通用名称(例如,你的名字)'与目标主机名'myservername.org'不匹配 – rix

+0

51 curl_setopt($ ch,CURLOPT_POST,true ); 52 curl_setopt($ ch,CURLOPT_URL,$ url); 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重定向 - 感谢您的帮助! 现在剩下的全部是这样的:*违反RFC 2616/10.3.2并从POST切换到GET 卷曲切换以在重定向时得到。无论如何要阻止这种情况发生? – rix

1

你得到返回301错误。您尝试的网址是http://servername.something.org,301表示该页面位于https://myserver(请注意https协议)。

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