我在我的本地机器上设置客户端/服务器测试场景 - 我有一个测试客户端PHP脚本,旨在通过cURL将XML-RPC发送到服务器PHP脚本。PHP/cURL - 服务器没有收到POST数据
$cnxn = curl_init();
$log = fopen("/var/www/mobile-client.localhost/www/curl.log", "w");
curl_setopt_array($cnxn,
array(
CURLOPT_FRESH_CONNECT => false,
CURLOPT_HEADER => false,
CURLOPT_HTTPHEADER => array(
"Content-Type: text/xml",
),
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => "m=boomshakalaka",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_STDERR => $log,
CURLOPT_URL => "http://mobile-server.localhost/rpc/index.php",
CURLOPT_VERBOSE => true,
)
);
$response = curl_exec($cnxn);
echo "<pre>";
var_dump(curl_errno($cnxn) . ':' . curl_error($cnxn), "<hr>", $response);
fclose($log);
curl_close($cnxn);
然而,当服务器通过(使用var_dump($_POST)
)返回POST数组的内容作出响应,该响应是空的。
我在/var/www/mobile-client.localhost/www/curl.log
有以下内容创建的日志文件的内容:
* About to connect() to mobile-server.localhost port 80 (#0)
* Trying 127.0.0.1... * connected
* Connected to mobile-server.localhost (127.0.0.1) port 80 (#0)
> POST /rpc/index.php HTTP/1.1
Host: mobile-server.localhost
Accept: */*
Content-Type: text/xml
Content-Length: 15
< HTTP/1.1 200 OK
< Date: Tue, 25 Jan 2011 04:57:15 GMT
< Server: Apache/2.2.14 (Ubuntu)
< X-Powered-By: PHP/5.3.2-1ubuntu4.7
< Vary: Accept-Encoding
< Content-Length: 1337
< Content-Type: text/html
<
* Connection #0 to host mobile-server.localhost left intact
* Closing connection #0
我还监视我的Wireshark的环回地址,并查看捕获日志如下:
POST /rpc/index.php HTTP/1.1
Host: mobile-server.localhost
Accept: */*
Content-Type: text/xml
Content-Length: 15
m=boomshakalaka
我的POST数据在哪里消失?
对于那些有兴趣在实际的服务器响应 - index.php文件的内容是:
<?php
var_dump(":)");
var_dump("POST: ", $_POST);
var_dump("GET: ", $_GET);
var_dump("SERVER: ", $_SERVER);
`的Content-Length:1337` ...有趣。 `var_dump($ response)`给你什么? – 2011-01-25 06:02:29
编辑帖子以显示服务器的脚本 – HorusKol 2011-01-25 06:06:09