卷曲和PHP在发送POST数据 [英] Sending POST data with curl and php

查看:201
本文介绍了卷曲和PHP在发送POST数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

映入眼帘。

所以,我在Amazon EC2上运行Fedora Core 8。我安装httpd的,PHP5和libcurl的,和一堆其他的东西。似乎是伟大的工作,但后来我意识到,POST数据不被卷曲在我的PHP脚本发送。在命令行同样的要求工作寿。我也跑了我的本地机器(Win XP的),另一个远程机器(Ubuntu的)在同一个PHP脚本,它们运行良好,POST数据被发送,但不是在FC8。是否需要任何特殊的配置?任何防火墙问题?

So, I'm running Fedora Core 8 on an Amazon EC2. I installed httpd, php5 and libcurl, and a bunch of other stuff. Seemed to be working great, but then I realized that POST data isn't being sent by curl in my php scripts. Same request in the command line works tho. I also ran the same php scripts on my local machine (Win XP) and another remote machine (Ubuntu), and they run fine, the POST data is being sent, but not on the FC8. Does it require any special configuration? Any firewall issues?

下面是PHP的code:

Here's the PHP code:

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);

下面是相应的curl命令:

Here's the corresponding curl command:

curl -d "something=somethingelse" http://foller.me/tmp/postdump.php

我还发现在Apache的error_log相应的条目,这里就是我想出了:

I also found the corresponding entry in the apache error_log, and here's what I came up with:

* 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

不被发送的POST数据,看到了吗?任何想法?

The POST data isn't being sent, see? Any ideas?

在此先感谢大家。
〜ķ。

Thanks in advance everyone. ~ K.

推荐答案

看起来好像这原来从POST请求到GET:

Looks as if this turns the request from POST to GET:

curl_setopt($ch, CURLOPT_NOBODY, 0);

删除线和它的作品。

Remove that line and it works.

CURLOPT_NOBODY

一个非零参数告诉库不包括
  身体部分中的输出。这仅是相关
  有单独的头和身体部位协议。

A non-zero parameter tells the library to not include the body-part in the output. This is only relevant for protocols that have separate header and body parts.

这篇关于卷曲和PHP在发送POST数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆