kov*_*nin 4 php linux apache curl
映入眼帘.
所以,我在Amazon EC2上运行Fedora Core 8.我安装了httpd,php5和libcurl,以及其他一些东西.似乎工作得很好,但后来我意识到我的PHP脚本中没有curl发送POST数据.在命令行中的相同请求工作.我也在我的本地机器(Win XP)和另一台远程机器(Ubuntu)上运行相同的php脚本,它们运行正常,POST数据正在发送,但不在FC8上.它需要任何特殊配置吗?任何防火墙问题?
这是PHP代码:
error_reporting(E_ALL);
$ch = curl_init("http://foller.me/tmp/postdump.php");
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "something=somewhere");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_NOBODY, 0);
$response = curl_exec($ch);
echo $response;
curl_close($ch);
Run Code Online (Sandbox Code Playgroud)
这是相应的curl命令:
curl -d "something=somethingelse" http://foller.me/tmp/postdump.php
Run Code Online (Sandbox Code Playgroud)
我还在apache error_log中找到了相应的条目,这就是我想出的:
* About to connect() to foller.me port 80 (#0)
* Trying 75.101.138.148... * connected
* Connected to foller.me (75.101.138.148) port 80 (#0)
> GET /tmp/postdump.php HTTP/1.1
Host: foller.me
Accept: */*
< HTTP/1.1 200 OK
< Date: Tue, 07 Jul 2009 10:32:18 GMT
< Server: Apache/2.2.9 (Fedora)
< X-Powered-By: PHP/5.2.6
< Content-Length: 31
< Connection: close
< Content-Type: text/html; charset=UTF-8
<
* Closing connection #0
Run Code Online (Sandbox Code Playgroud)
POST数据没有发送,请参阅?有任何想法吗?
在此先感谢大家.~K
看起来好像这会将请求从POST转到GET:
curl_setopt($ch, CURLOPT_NOBODY, 0);
Run Code Online (Sandbox Code Playgroud)
删除该行,它的工作原理.
CURLOPT_NOBODY
非零参数告诉库不在输出中包含正文部分.这仅适用于具有单独标题和正文部分的协议.
| 归档时间: |
|
| 查看次数: |
8389 次 |
| 最近记录: |