我正在本地机器上建立一个客户端/服务器测试场景 - 我有一个测试客户端PHP脚本,旨在通过cURL将XML-RPC发送到服务器PHP脚本。
$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);
然而,当服务器通过返回POST数组的内容(使用var_dump($_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)
会给你什么? - Salman A