2014-09-01 65 views
0

我有一个网站,我想发布数据。问题是,当使用cakephp httpsocket功能时,设置自定义端口(例如8080)将导致端口位于url的末尾(而不是主机名的末尾)。见示例代码:CakePHP:httpsocket和自定义端口导致错误的网址

$notificationUrl = 'www.example.com/LotsController/sendWork'; 

$request = array(
    'method' => 'POST', 
    'uri' => array(
     'scheme' => 'http', 
     'host' => $notificationUrl, 
     'port' => 8080, 
     // 'user' => null, 
     // 'pass' => null, 
     // 'path' => null, 
     // 'query' => null, 
     // 'fragment' => null 
    ), 
    // 'auth' => array(
     // 'method' => 'Basic', 
     // 'user' => null, 
     // 'pass' => null 
    //), 
    // 'version' => '1.1', 
    'body' => $jsonWithEncryptedData, 
    // 'line' => null, 
    // 'header' => array(
     // 'Connection' => 'close', 
     // 'User-Agent' => 'CakePHP' 
    //), 
    // 'raw' => null, 
    // 'redirect' => false, 
    // 'cookies' => array() 
); 
     $HttpSocket = new HttpSocket(); 

     $HTTPPostResults = $HttpSocket->post($notificationUrl, $jsonWithEncryptedData , $request); 

返回的响应HTML代码(状态404)显示的URL CakePHP的httpsocket尝试连接到的是: http://www.example.com/LotsController/sendWork:8080(不在浏览器中运行)

它不应该是: http://www.example.com:8080/LotsController/sendWork(在浏览器中工作)

为什么cakephp将端口号放在url的末尾?

我的设置: Ubuntu的14 CakePHP的2.5.3

回答

1

主机是您想要连接是

www.example.com 

不是URL中的基本域

www.example.com/LotsController/sendWork 

您应该在路径中包含其他信息而不是主机