使用curl在php中发布与faye的数据

据faye的作者,我可以从任何平台发送消息
用curl发布消息的格式是:

curl -X POST http://192.168.1.101:8000/faye -H 'Content-Type: application/json' -d '{"channel":"/foo","data":{"hello":"world"}}' 

我格式化前面的行在PHP中使用

 $data = array("channel" => "/one", "result" => "Hello World from PHP!!"); $data_string=json_encode($data); $ch = curl_init('http://192.168.1.101:8000/faye'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST"); curl_setopt($ch,CURLOPT_POSTFIELDS,$data_string); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_HTTPHEADER,array( 'Content-Type:application/json','Content-Length:'strlen($data_string))); $result = curl_exec($ch); 

不知怎的,用户通道一个不会得到结果

Java脚本中的发布function无缝工作(请参见下面的行)

 var publication = client.publish('/one',{ result: 'Hello World from JS'});<br/> 

请让我知道什么是失踪或我的错误,谢谢

这个为我工作:

 $data = array("channel" => "/one", "data" => array ("result"=>"HelloWorld from PHP!!")); $data_string=json_encode($data); $ch = curl_init('http://localhost:8000/faye'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST"); curl_setopt($ch,CURLOPT_POSTFIELDS,$data_string); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-Type:application/json')); echo $result = curl_exec($ch);